]> granicus.if.org Git - shadow/commitdiff
* libmisc/limits.c: Avoid implicit conversion of integer to
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 22 Aug 2010 19:13:53 +0000 (19:13 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 22 Aug 2010 19:13:53 +0000 (19:13 +0000)
boolean.
* libmisc/basename.c: Avoid implicit conversion of pointer to
boolean.
* libmisc/basename.c, lib/prototypes.h (Basename): Return a
constant string.
* libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
splint annotations.
* libmisc/chowndir.c: Avoid memory leak.
* libmisc/chowndir.c: Do not check *printf/*puts return value.
* libmisc/chowntty.c: Avoid implicit conversion between integer
types.
* libmisc/obscure.c: Return a bool when possible instead of int.
* libmisc/shell.c: Do not check *printf/*puts return value.
* libmisc/shell.c: Do not check execle return value.
* libmisc/setupenv.c: Avoid implicit conversion between integer
types.
* libmisc/xmalloc.c: size should not be zero to avoid returning
NULL pointers.
* libmisc/hushed.c: Do not check *printf/*puts return value.
* libmisc/system.c: Avoid implicit conversion of integer to
boolean. safe_system last argument is a boolean.
* libmisc/system.c: Check return value of dup2.
* libmisc/system.c: Do not check *printf/*puts return value.
* libmisc/system.c: Do not check execve return value.
* libmisc/salt.c: Do not check *printf/*puts return value.
* libmisc/loginprompt.c: Do not check gethostname return value.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
gr_rewind/pw_rewind return value.
* libmisc/ttytype.c: Limit the number of parsed characters in the
sscanf format.
* libmisc/ttytype.c: Test if a type was really read.
* libmisc/sub.c: Do not check *printf/*puts return value.
* libmisc/sub.c: Avoid implicit conversion of integer to boolean.
* src/userdel.c: Fix typo in comment.
* src/userdel.c: Avoid implicit conversion of boolean to integer.
* src/userdel.c: safe_system last argument is a boolean.
* src/newusers.c: Avoid implicit conversion of boolean to integer.
* src/newusers.c: Avoid implicit conversion of integer to boolean.
* src/usermod.c: Add brackets.
* src/usermod.c: Avoid implicit conversion of characters or
integers to booleans.
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Add brackets.
* src/useradd.c: Avoid implicit conversion of characters or
integers to booleans.

28 files changed:
ChangeLog
lib/prototypes.h
libmisc/basename.c
libmisc/chowndir.c
libmisc/chowntty.c
libmisc/failure.c
libmisc/find_new_gid.c
libmisc/find_new_uid.c
libmisc/getdate.h
libmisc/getgr_nam_gid.c
libmisc/hushed.c
libmisc/limits.c
libmisc/loginprompt.c
libmisc/obscure.c
libmisc/salt.c
libmisc/setupenv.c
libmisc/shell.c
libmisc/sub.c
libmisc/system.c
libmisc/ttytype.c
libmisc/valid.c
libmisc/xmalloc.c
src/newusers.c
src/su.c
src/useradd.c
src/userdel.c
src/usermod.c
src/vipw.c

index 74ccce4c81ab05110e4efc15ff0847f24aef6ec6..86658fbeef0d7174cabdbeb70699eb9c8ebcc23f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,55 @@
+2010-08-22  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * libmisc/limits.c: Avoid implicit conversion of integer to
+       boolean.
+       * libmisc/basename.c: Avoid implicit conversion of pointer to
+       boolean.
+       * libmisc/basename.c, lib/prototypes.h (Basename): Return a
+       constant string.
+       * libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
+       libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
+       libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
+       splint annotations.
+       * libmisc/chowndir.c: Avoid memory leak.
+       * libmisc/chowndir.c: Do not check *printf/*puts return value.
+       * libmisc/chowntty.c: Avoid implicit conversion between integer
+       types.
+       * libmisc/obscure.c: Return a bool when possible instead of int.
+       * libmisc/shell.c: Do not check *printf/*puts return value.
+       * libmisc/shell.c: Do not check execle return value.
+       * libmisc/setupenv.c: Avoid implicit conversion between integer
+       types.
+       * libmisc/xmalloc.c: size should not be zero to avoid returning
+       NULL pointers.
+       * libmisc/hushed.c: Do not check *printf/*puts return value.
+       * libmisc/system.c: Avoid implicit conversion of integer to
+       boolean. safe_system last argument is a boolean.
+       * libmisc/system.c: Check return value of dup2.
+       * libmisc/system.c: Do not check *printf/*puts return value.
+       * libmisc/system.c: Do not check execve return value. 
+       * libmisc/salt.c: Do not check *printf/*puts return value.
+       * libmisc/loginprompt.c: Do not check gethostname return value.
+       * libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
+       gr_rewind/pw_rewind return value.
+       * libmisc/ttytype.c: Limit the number of parsed characters in the
+       sscanf format.
+       * libmisc/ttytype.c: Test if a type was really read.
+       * libmisc/sub.c: Do not check *printf/*puts return value.
+       * libmisc/sub.c: Avoid implicit conversion of integer to boolean.
+       * src/userdel.c: Fix typo in comment.
+       * src/userdel.c: Avoid implicit conversion of boolean to integer.
+       * src/userdel.c: safe_system last argument is a boolean.
+       * src/newusers.c: Avoid implicit conversion of boolean to integer.
+       * src/newusers.c: Avoid implicit conversion of integer to boolean.
+       * src/usermod.c: Add brackets.
+       * src/usermod.c: Avoid implicit conversion of characters or
+       integers to booleans.
+       * src/vipw.c: Avoid implicit conversion of integer to boolean.
+       * src/su.c: Avoid implicit conversion of integer to boolean.
+       * src/su.c: Add brackets.
+       * src/useradd.c: Avoid implicit conversion of characters or
+       integers to booleans.
+
 2010-08-22  Nicolas François  <nicolas.francois@centraliens.net>
 
        * libmisc/obscure.c, lib/prototypes.h (obscure): Return a bool
index a0f3ffa527aaad5e5bca8ecad0adc911155b7ed0..8f9db9c634190fc59daf0b1b690e574bc688191b 100644 (file)
@@ -57,7 +57,7 @@
 #include "defines.h"
 #include "commonio.h"
 
-extern char *Prog;
+extern /*@observer@*/ const char *Prog;
 
 /* addgrps.c */
 #if defined (HAVE_SETGROUPS) && ! defined (USE_PAM)
@@ -72,7 +72,7 @@ extern int isexpired (const struct passwd *, /*@null@*/const struct spwd *);
 
 /* basename() renamed to Basename() to avoid libc name space confusion */
 /* basename.c */
-extern char *Basename (char *str);
+extern /*@observer@*/const char *Basename (char *str);
 
 /* chowndir.c */
 extern int chown_tree (const char *root,
@@ -156,7 +156,7 @@ extern int find_new_uid (bool sys_user,
 extern int get_gid (const char *gidstr, gid_t *gid);
 
 /* getgr_nam_gid.c */
-extern /*@null@*/struct group *getgr_nam_gid (const char *grname);
+extern /*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname);
 
 /* getlong.c */
 extern int getlong (const char *numstr, /*@out@*/long int *result);
@@ -340,8 +340,8 @@ extern int shell (const char *file, /*@null@*/const char *arg, char *const envp[
 /* system.c */
 extern int safe_system (const char *command,
                         const char *argv[],
-                        const char *env[],
-                        int ignore_stderr);
+                        /*@null@*/const char *env[],
+                        bool ignore_stderr);
 
 /* strtoday.c */
 extern long strtoday (const char *);
@@ -391,9 +391,9 @@ extern int setutmpx (struct utmpx *utx);
 extern bool valid (const char *, const struct passwd *);
 
 /* xmalloc.c */
-extern /*@maynotreturn@*/ /*@out@*//*@only@*/char *xmalloc (size_t size)
+extern /*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/char *xmalloc (size_t size)
   /*@ensures MaxSet(result) == (size - 1); @*/;
-extern /*@maynotreturn@*/ /*@only@*/char *xstrdup (const char *);
+extern /*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *);
 
 /* xgetpwnam.c */
 extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *);
index b1962b848a6b7d7a13160a6265e1b0cc8494acdc..0022aae977e5963851a998c78f0f5611365d48d9 100644 (file)
@@ -42,9 +42,9 @@
 
 #include "defines.h"
 #include "prototypes.h"
-char *Basename (char *str)
+/*@observer@*/const char *Basename (char *str)
 {
        char *cp = strrchr (str, '/');
 
-       return cp ? cp + 1 : str;
+       return (NULL != cp) ? cp + 1 : str;
 }
index 5179c6bffce85a1daad80466d8bdc19401a60dca..b297350991063601d89da006d82db79f57734c7a 100644 (file)
@@ -78,6 +78,7 @@ int chown_tree (const char *root,
         */
 
        if (access (root, F_OK) != 0) {
+               free (new_name);
                return -1;
        }
 
@@ -90,6 +91,7 @@ int chown_tree (const char *root,
 
        dir = opendir (root);
        if (NULL == dir) {
+               free (new_name);
                return -1;
        }
 
@@ -120,7 +122,7 @@ int chown_tree (const char *root,
                        new_name_len += 1024;
                }
 
-               snprintf (new_name, new_name_len, "%s/%s", root, ent->d_name);
+               (void) snprintf (new_name, new_name_len, "%s/%s", root, ent->d_name);
 
                /* Don't follow symbolic links! */
                if (LSTAT (new_name, &sb) == -1) {
index 0b2d9fb483e1867923cfb551f9e7a8194f4988bb..f6f5dbc567cf154ad86ab08237c1ba291c746332 100644 (file)
@@ -72,7 +72,7 @@ void chown_tty (const struct passwd *info)
         */
 
        if (   (fchown (STDIN_FILENO, info->pw_uid, gid) != 0)
-           || (fchmod (STDIN_FILENO, getdef_num ("TTYPERM", 0600)) != 0)) {
+           || (fchmod (STDIN_FILENO, (mode_t)getdef_num ("TTYPERM", 0600)) != 0)) {
                int err = errno;
 
                fprintf (stderr,
index 8277836a9e1e8de1595252c70483f844e88a74aa..f6390a796d58618d468dbd933c256a62baa11aa5 100644 (file)
@@ -273,12 +273,14 @@ void failprint (const struct faillog *fail)
                lasttime++;
        }
 #endif
+       /*@-formatconst@*/
        (void) printf (ngettext ("%d failure since last login.\n"
                                 "Last was %s on %s.\n",
                                 "%d failures since last login.\n"
                                 "Last was %s on %s.\n",
                                 (unsigned long) fail->fail_cnt),
                       fail->fail_cnt, lasttime, fail->fail_line);
+       /*@=formatconst@*/
 }
 
 /*
index 8c54639cd6dfc43ae0dfe24f7128ebacd7e9563c..ce534b6233f805927f70b017d24db16e022908cd 100644 (file)
@@ -115,7 +115,7 @@ int find_new_gid (bool sys_group,
                        }
                }
 
-               gr_rewind ();
+               (void) gr_rewind ();
                while ((grp = gr_next ()) != NULL) {
                        if ((grp->gr_gid <= group_id) && (grp->gr_gid >= gid_min)) {
                                group_id = grp->gr_gid - 1;
@@ -139,7 +139,7 @@ int find_new_gid (bool sys_group,
                }
                endgrent ();
 
-               gr_rewind ();
+               (void) gr_rewind ();
                while ((grp = gr_next ()) != NULL) {
                        if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {
                                group_id = grp->gr_gid + 1;
index 7b330c28520181c159b96f5130eab33d9a51c4f5..6077eb1e8c1782ff97eb266fd8ab6d10a79874e6 100644 (file)
@@ -115,7 +115,7 @@ int find_new_uid (bool sys_user,
                        }
                }
 
-               pw_rewind ();
+               (void) pw_rewind ();
                while ((pwd = pw_next ()) != NULL) {
                        if ((pwd->pw_uid <= user_id) && (pwd->pw_uid >= uid_min)) {
                                user_id = pwd->pw_uid - 1;
@@ -139,7 +139,7 @@ int find_new_uid (bool sys_user,
                }
                endpwent ();
 
-               pw_rewind ();
+               (void) pw_rewind ();
                while ((pwd = pw_next ()) != NULL) {
                        if ((pwd->pw_uid >= user_id) && (pwd->pw_uid <= uid_max)) {
                                user_id = pwd->pw_uid + 1;
index d59b70a945f55e6ba9c17e1ab78a7b93c9aa9375..d1bb176dad0b3613edfd116ff2e1e8e38f1ebb3a 100644 (file)
@@ -35,5 +35,5 @@
 #include <config.h>
 #include "defines.h"
 
-time_t get_date (const char *, const time_t *);
+time_t get_date (const char *p, /*@null@*/const time_t *now);
 #endif
index 39e44193c29107bec91a1aa9035493442f329ba5..b2556c410d3c5782dda778cad4e553cbc2556050 100644 (file)
@@ -44,7 +44,7 @@
  * The string may be a valid GID or a valid groupname.
  * If the group does not exist on the system, NULL is returned.
  */
-extern /*@null@*/struct group *getgr_nam_gid (const char *grname)
+extern /*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname)
 {
        long long int gid;
        char *endptr;
index 374d5f290b087bfad063d6480c80388e75e6f0e2..b71b99ce2b53a25ef26353fb9252984ebe19255e 100644 (file)
@@ -76,7 +76,7 @@ bool hushed (const char *username)
         */
 
        if (hushfile[0] != '/') {
-               snprintf (buf, sizeof (buf), "%s/%s", pw->pw_dir, hushfile);
+               (void) snprintf (buf, sizeof (buf), "%s/%s", pw->pw_dir, hushfile);
                return (access (buf, F_OK) == 0);
        }
 
index 016427c1d57fb54c81b2f516367749c455daf879..1dc316ab9407102c56142abcdfd226596f61516e 100644 (file)
@@ -547,8 +547,7 @@ void setup_limits (const struct passwd *info)
        if (getdef_bool ("QUOTAS_ENAB")) {
 #ifdef LIMITS
                if (info->pw_uid != 0) {
-                       if (setup_user_limits (info->pw_name) &
-                           LOGIN_ERROR_LOGIN) {
+                       if ((setup_user_limits (info->pw_name) & LOGIN_ERROR_LOGIN) != 0) {
                                (void) fputs (_("Too many logins.\n"), stderr);
                                (void) sleep (2); /* XXX: Should be FAIL_DELAY */
                                exit (EXIT_FAILURE);
index af27c408fed62321f39f83b44f013f54187fc5a2..239bc175e9f24bedbfe52d2a203aee0ea306514b 100644 (file)
@@ -98,7 +98,7 @@ void login_prompt (const char *prompt, char *name, int namesize)
                                (void) fclose (fp);
                        }
                }
-               gethostname (buf, sizeof buf);
+               (void) gethostname (buf, sizeof buf);
                printf (prompt, buf);
                (void) fflush (stdout);
        }
index 8aaab3b2a6368f0d8602fa9ecf2dd0790d6e6069..a075123703052cbd56c716e18564a7c0ba409aab 100644 (file)
@@ -69,7 +69,7 @@ static bool palindrome (unused const char *old, const char *new)
  * more than half of the characters are different ones.
  */
 
-static bool similar (const char *old, const char *new)
+static bool similar (/*@notnull@*/const char *old, /*@notnull@*/const char *new)
 {
        int i, j;
 
@@ -100,7 +100,7 @@ static bool similar (const char *old, const char *new)
  * a nice mix of characters.
  */
 
-static int simple (unused const char *old, const char *new)
+static bool simple (unused const char *old, const char *new)
 {
        bool digits = false;
        bool uppers = false;
@@ -147,7 +147,7 @@ static int simple (unused const char *old, const char *new)
        return true;
 }
 
-static char *str_lower (char *string)
+static char *str_lower (/*@returned@*/char *string)
 {
        char *cp;
 
@@ -157,8 +157,10 @@ static char *str_lower (char *string)
        return string;
 }
 
-static const char *password_check (const char *old, const char *new,
-                                  const struct passwd *pwdp)
+static /*@observer@*//*@null@*/const char *password_check (
+       /*@notnull@*/const char *old,
+       /*@notnull@*/const char *new,
+       /*@notnull@*/const struct passwd *pwdp)
 {
        const char *msg = NULL;
        char *oldmono, *newmono, *wrapped;
@@ -219,9 +221,10 @@ static const char *password_check (const char *old, const char *new,
        return msg;
 }
 
-/*ARGSUSED*/
-static const char *obscure_msg (const char *old, const char *new,
-                                   const struct passwd *pwdp)
+static /*@observer@*//*@null@*/const char *obscure_msg (
+       /*@notnull@*/const char *old,
+       /*@notnull@*/const char *new,
+       /*@notnull@*/const struct passwd *pwdp)
 {
        size_t maxlen, oldlen, newlen;
        char *new1, *old1;
index 99233c6897f0714a5d83b7e100db6206c8c81890..dcf39de0c7bca863cf588a8d07c23cbb56793ba3 100644 (file)
@@ -150,7 +150,7 @@ static /*@observer@*/const char *SHA_salt_rounds (/*@null@*/int *prefered_rounds
                rounds = ROUNDS_MAX;
        }
 
-       snprintf (rounds_prefix, 18, "rounds=%ld$", rounds);
+       (void) snprintf (rounds_prefix, 18, "rounds=%ld$", rounds);
 
        /* Sanity checks. That should not be necessary. */
        rounds_prefix[17] = '\0';
index cb67361bc136c2cc2cb163cba4e3eb0efce973b2..74170e8195de4254720ae2bb314d536fce80a60c 100644 (file)
@@ -74,7 +74,7 @@ static void read_env_file (const char *filename)
        if (NULL == fp) {
                return;
        }
-       while (fgets (buf, sizeof buf, fp) == buf) {
+       while (fgets (buf, (int)(sizeof buf), fp) == buf) {
                cp = strrchr (buf, '\n');
                if (NULL == cp) {
                        break;
index e253ae3ff864ed71b4c32c983ca5221a9560247a..92bfc2bc840a074426f49888768a416ef9f66d1c 100644 (file)
@@ -68,7 +68,8 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
         * don't want to tell us what it is themselves.
         */
        if (arg == (char *) 0) {
-               snprintf (arg0, sizeof arg0, "-%s", Basename ((char *) file));
+               (void) snprintf (arg0, sizeof arg0, "-%s", Basename ((char *) file));
+               arg0[sizeof arg0 - 1] = '\0';
                arg = arg0;
        }
 
@@ -77,7 +78,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
         * able to figure out what we are up to without too much
         * grief.
         */
-       execle (file, arg, (char *) 0, envp);
+       (void) execle (file, arg, (char *) 0, envp);
        err = errno;
 
        if (access (file, R_OK|X_OK) == 0) {
@@ -85,7 +86,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
                 * Assume this is a shell script (with no shebang).
                 * Interpret it with /bin/sh
                 */
-               execle (SHELL, "sh", "-", file, (char *)0, envp);
+               (void) execle (SHELL, "sh", "-", file, (char *)0, envp);
                err = errno;
        }
 
@@ -94,7 +95,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[])
         * how to execute this stupid shell, so I might as well give
         * up in disgust ...
         */
-       snprintf (arg0, sizeof arg0, _("Cannot execute %s"), file);
+       (void) snprintf (arg0, sizeof arg0, _("Cannot execute %s"), file);
        errno = err;
        perror (arg0);
        return err;
index ed879c206cd843653f9474b21970a9415eb02821..36ac396ca7cc45d50dd33751f4efcc76825fa682 100644 (file)
@@ -66,11 +66,13 @@ void subsystem (const struct passwd *pw)
         * must be able to change into it.
         */
 
-       if (chdir (pw->pw_dir) || chroot (pw->pw_dir)) {
-               printf (_("Can't change root directory to '%s'\n"),
-                       pw->pw_dir);
+       if (   (chdir (pw->pw_dir) != 0)
+           || (chroot (pw->pw_dir) != 0)) {
+               (void) printf (_("Can't change root directory to '%s'\n"),
+                              pw->pw_dir);
                SYSLOG ((LOG_WARN, NO_SUBROOT2, pw->pw_dir, pw->pw_name));
                closelog ();
                exit (EXIT_FAILURE);
        }
 }
+
index bcd7bb7e264de214bcc353e28fb1a6d2291081f7..95054165e56fa17413491a5c16a638af9ef10ba6 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2009       , Dan Walsh <dwalsh@redhat.com>
+ * Copyright (c) 2010       , Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,8 +39,8 @@
 
 int safe_system (const char *command,
                  const char *argv[],
-                 const char *env[],
-                 int ignore_stderr)
+                 /*@null@*/const char *env[],
+                 bool ignore_stderr)
 {
        int status = -1;
        int fd;
@@ -50,7 +51,7 @@ int safe_system (const char *command,
                return -1;
        }
 
-       if (pid) {       /* Parent */
+       if (pid != 0) {       /* Parent */
                if (waitpid (pid, &status, 0) > 0) {
                        return status;
                } else {
@@ -60,13 +61,19 @@ int safe_system (const char *command,
 
        fd = open ("/dev/null", O_RDWR);
        /* Child */
-       dup2 (fd, 0);           /* Close Stdin */
+       /* Close Stdin */
+       if (dup2 (fd, 0) == -1) {
+               exit (EXIT_FAILURE);
+       }
        if (ignore_stderr) {
-               dup2 (fd, 2);   /* Close Stderr */
+               /* Close Stderr */
+               if (dup2 (fd, 2) == -1) {
+                       exit (EXIT_FAILURE);
+               }
        }
 
-       execve (command, (char *const *) argv, (char *const *) env);
-       fprintf (stderr, _("Failed to exec '%s'\n"), argv[0]);
+       (void) execve (command, (char *const *) argv, (char *const *) env);
+       (void) fprintf (stderr, _("Failed to exec '%s'\n"), argv[0]);
        exit (EXIT_FAILURE);
 }
 
index aa31dfe504b5a014db59c7e49aaa2d31a5392121..06e7944429eb59262fe047474c5f4bdf6b0cffde 100644 (file)
@@ -47,8 +47,8 @@ void ttytype (const char *line)
        char buf[BUFSIZ];
        const char *typefile;
        char *cp;
-       char type[BUFSIZ];
-       char port[BUFSIZ];
+       char type[1024] = "";
+       char port[1024];
 
        if (getenv ("TERM") != NULL) {
                return;
@@ -76,12 +76,12 @@ void ttytype (const char *line)
                        *cp = '\0';
                }
 
-               if ((sscanf (buf, "%s %s", type, port) == 2) &&
-                   (strcmp (line, port) == 0)) {
+               if (   (sscanf (buf, "%1023s %1023s", type, port) == 2)
+                   && (strcmp (line, port) == 0)) {
                        break;
                }
        }
-       if ((feof (fp) == 0) && (ferror (fp) == 0)) {
+       if ((feof (fp) == 0) && (ferror (fp) == 0) && (type[0] != '\0')) {
                addenv ("TERM", type);
        }
 
index 42c0dbc3b1c56ab0510af33fac92d83357c454e0..aa0390a550749e5e1a9ae93b3d130965a711bb83 100644 (file)
@@ -52,7 +52,7 @@
 bool valid (const char *password, const struct passwd *ent)
 {
        const char *encrypted;
-       const char *salt;
+       /*@observer@*/const char *salt;
 
        /*
         * Start with blank or empty password entries.  Always encrypt
index 6c34d9b23d36c090ab0ed04e3947b2cb90d43288..665de65cd8a2f50911149da9766d4d0d85f073f4 100644 (file)
 #include "defines.h"
 #include "prototypes.h"
 
-char *xmalloc (size_t size)
+/*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/char *xmalloc (size_t size)
 {
        char *ptr;
 
        ptr = (char *) malloc (size);
-       if ((NULL == ptr) && (0 != size)) {
-               fprintf (stderr, _("malloc(%d) failed\n"), (int) size);
+       if (NULL == ptr) {
+               (void) fprintf (stderr, _("malloc(%d) failed\n"), (int) size);
                exit (13);
        }
        return ptr;
 }
 
-char *xstrdup (const char *str)
+/*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *str)
 {
        return strcpy (xmalloc (strlen (str) + 1), str);
 }
index 85b2a959a7eda8c0b599da3ab46182e4d45d4ff7..62cd3daa79613aa5655e79a62f02107c60d25126 100644 (file)
@@ -378,7 +378,7 @@ static int add_user (const char *name, uid_t uid, gid_t gid)
        pwent.pw_dir = "";      /* XXX warning: const */
        pwent.pw_shell = "";    /* XXX warning: const */
 
-       return (pw_update (&pwent) == 0);
+       return (pw_update (&pwent) == 0) ? -1 : 0;
 }
 
 #ifndef USE_PAM
@@ -976,7 +976,7 @@ int main (int argc, char **argv)
                usernames[nusers-1] = strdup (fields[0]);
                passwords[nusers-1] = strdup (fields[1]);
 #endif                         /* USE_PAM */
-               if (add_passwd (&newpw, fields[1])) {
+               if (add_passwd (&newpw, fields[1]) != 0) {
                        fprintf (stderr,
                                 _("%s: line %d: can't update password\n"),
                                 Prog, line);
index 9ef0b210cc10688715e694c921c48116c1ca0918..304bb2815c99c7cf2dc88c5fc2867de2486c8312 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -127,12 +127,13 @@ static RETSIGTYPE die (int killed)
 {
        static TERMIO sgtty;
 
-       if (killed)
+       if (killed != 0) {
                STTY (0, &sgtty);
-       else
+       } else {
                GTTY (0, &sgtty);
+       }
 
-       if (killed) {
+       if (killed != 0) {
                closelog ();
                exit (128+killed);
        }
@@ -813,8 +814,9 @@ int main (int argc, char **argv)
         * The first character of an administrator defined method is an '@'
         * character.
         */
-       if (!amroot && pw_auth (pwent.pw_passwd, name, PW_SU, (char *) 0)) {
-               SYSLOG ((pwent.pw_uid ? LOG_NOTICE : LOG_WARN,
+       if (   !amroot
+           && (pw_auth (pwent.pw_passwd, name, PW_SU, (char *) 0) != 0)) {
+               SYSLOG (((pwent.pw_uid != 0)? LOG_NOTICE : LOG_WARN,
                         "Authentication failed for %s", name));
                fprintf(stderr, _("%s: Authentication failure\n"), Prog);
                su_failure (tty);
@@ -831,7 +833,7 @@ int main (int argc, char **argv)
                        spwd = pwd_to_spwd (&pwent);
                }
 
-               if (expire (&pwent, spwd)) {
+               if (expire (&pwent, spwd) != 0) {
                        /* !USE_PAM, no need for xgetpwnam */
                        struct passwd *pwd = getpwnam (name);
 
index 661d6bccf19c201f4173760b8ef0a32d4369bf81..0b15a8f588c5d9f4cff1779950aa79c34b78a3ef 100644 (file)
@@ -1731,7 +1731,7 @@ static void usr_update (void)
 static void selinux_update_mapping (void) {
        if (is_selinux_enabled () <= 0) return;
 
-       if (*user_selinux) { /* must be done after passwd write() */
+       if ('\0' != *user_selinux) { /* must be done after passwd write() */
                const char *argv[7];
                argv[0] = "/usr/sbin/semanage";
                argv[1] = "login";
@@ -1740,7 +1740,7 @@ static void selinux_update_mapping (void) {
                argv[4] = user_selinux;
                argv[5] = user_name;
                argv[6] = NULL;
-               if (safe_system (argv[0], argv, NULL, 0)) {
+               if (safe_system (argv[0], argv, NULL, false) != 0) {
                        fprintf (stderr,
                                 _("%s: warning: the user name %s to %s SELinux user mapping failed.\n"),
                                 Prog, user_name, user_selinux);
index 1423392098d0425c88f2f4e566bfea3b89e6eb45..817464ed84e76806ceaa47b6bc8dad832df300c4 100644 (file)
@@ -632,7 +632,7 @@ static bool path_prefix (const char *s1, const char *s2)
  *
  * Return
  *  1: path exists and is owned by uid
- *  0: path is not owned by uid, or a failure occured
+ *  0: path is not owned by uid, or a failure occurred
  * -1: path does not exist
  */
 static int is_owner (uid_t uid, const char *path)
@@ -648,7 +648,7 @@ static int is_owner (uid_t uid, const char *path)
                        return 0;
                }
        }
-       return (st.st_uid == uid);
+       return (st.st_uid == uid) ? 1 : 0;
 }
 
 static int remove_mailbox (void)
@@ -1043,7 +1043,7 @@ int main (int argc, char **argv)
                args[2] = "-d";
                args[3] = user_name;
                args[4] = NULL;
-               safe_system (args[0], args, NULL, 1);
+               safe_system (args[0], args, NULL, true);
        }
 #endif                         /* WITH_SELINUX */
 
index 22240abd850ee61d6e5e492b94f5e14359a8cf2e..5918cbd3688c11f64c55739221efa5266b415f90 100644 (file)
@@ -1851,9 +1851,11 @@ int main (int argc, char **argv)
 static void selinux_update_mapping (void) {
        const char *argv[7];
 
-       if (is_selinux_enabled () <= 0) return;
+       if (is_selinux_enabled () <= 0) {
+               return;
+       }
 
-       if (*user_selinux) {
+       if ('\0' != *user_selinux) {
                argv[0] = "/usr/sbin/semanage";
                argv[1] = "login";
                argv[2] = "-m";
@@ -1861,9 +1863,9 @@ static void selinux_update_mapping (void) {
                argv[4] = user_selinux;
                argv[5] = user_name;
                argv[6] = NULL;
-               if (safe_system (argv[0], argv, NULL, 1)) {
+               if (safe_system (argv[0], argv, NULL, true) != 0) {
                        argv[2] = "-a";
-                       if (safe_system (argv[0], argv, NULL, 0)) {
+                       if (safe_system (argv[0], argv, NULL, false) != 0) {
                                fprintf (stderr,
                                         _("%s: warning: the user name %s to %s SELinux user mapping failed.\n"),
                                         Prog, user_name, user_selinux);
index b5caf65ffb8afbb9ddc063b9264785a132ed0276..9f4118315d38e2597b079804d7ef355dfcbd0cc2 100644 (file)
@@ -231,7 +231,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
 #ifdef WITH_SELINUX
        /* if SE Linux is enabled then set the context of all new files
           to be the context of the file we are editing */
-       if (is_selinux_enabled ()) {
+       if (is_selinux_enabled () != 0) {
                security_context_t passwd_context=NULL;
                int ret = 0;
                if (getfilecon (file, &passwd_context) < 0) {
@@ -332,7 +332,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
        }
 #ifdef WITH_SELINUX
        /* unset the fscreatecon */
-       if (is_selinux_enabled ()) {
+       if (is_selinux_enabled () != 0) {
                if (setfscreatecon (NULL) != 0) {
                        vipwexit (_("setfscreatecon () failed"), errno, 1);
                }