]> granicus.if.org Git - shadow/commitdiff
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 23 Apr 2009 09:57:03 +0000 (09:57 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 23 Apr 2009 09:57:03 +0000 (09:57 +0000)
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.

16 files changed:
ChangeLog
lib/getdef.h
lib/getlong.c
lib/groupio.c
lib/gshadow_.h
lib/prototypes.h
lib/pwio.c
lib/sgroupio.c
lib/shadowio.c
libmisc/cleanup.c
libmisc/getgr_nam_gid.c
libmisc/list.c
libmisc/myname.c
libmisc/salt.c
libmisc/xgetXXbyYY.c
src/login.c

index 3f8be8fa91b1277e653a40bfffe31bae8ca0cfb5..442b578ca22a6c493f1d04249144fbc84392607a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-04-22  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
+       libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
+       lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
+       lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
+       lib/fputsx.c, lib/prototypes.h: Added splint annotations.
+       * lib/groupio.c: Avoid implicit conversion of pointers to
+       booleans.
+       * lib/groupio.c: Free allocated buffers in case of failure.
+
 2009-04-22  Nicolas François  <nicolas.francois@centraliens.net>
 
        * lib/defines.h: Added splint definitions to replace <locale.h>
index 39e02a23c1a1f066b3174878c8b248b84f48d49b..15e35ff753807248bd9821830d7114b79d9355a6 100644 (file)
@@ -38,7 +38,7 @@ extern long getdef_long (const char *, long);
 extern int getdef_num (const char *, int);
 extern unsigned long getdef_ulong (const char *, unsigned long);
 extern unsigned int getdef_unum (const char *, unsigned int);
-extern char *getdef_str (const char *);
+extern /*@observer@*/ /*@null@*/const char *getdef_str (const char *);
 extern int putdef_str (const char *, const char *);
 
 /* default UMASK value if not specified in /etc/login.defs */
index d1820847dabdc9cbe52ed070b2b8ac608df6c278..367ae9f898d6b4fa8e67824e16981ab8862f20dc 100644 (file)
@@ -42,7 +42,7 @@
  *
  * Returns 0 on failure, 1 on success.
  */
-int getlong (const char *numstr, long int *result)
+int getlong (const char *numstr, /*@out@*/long int *result)
 {
        long val;
        char *endptr;
index 965a430c66e1eeed656162b97028a4afb98c3cef..72b5c9499fe4b957353311d726374e72b8eb8ce1 100644 (file)
 #include "getdef.h"
 #include "groupio.h"
 
-static struct commonio_entry *merge_group_entries (struct commonio_entry *gr1,
-                                                   struct commonio_entry *gr2);
+static /*@null@*/struct commonio_entry *merge_group_entries (
+       /*@null@*/struct commonio_entry *gr1,
+       /*@null@*/struct commonio_entry *gr2);
 static int split_groups (unsigned int max_members);
 static int group_open_hook (void);
 
-static void *group_dup (const void *ent)
+static /*@null@*/ /*@only@*/void *group_dup (const void *ent)
 {
        const struct group *gr = ent;
 
@@ -245,8 +246,8 @@ static int group_open_hook (void)
                return 1;
        }
 
-       for (gr1 = group_db.head; gr1; gr1 = gr1->next) {
-               for (gr2 = gr1->next; gr2; gr2 = gr2->next) {
+       for (gr1 = group_db.head; NULL != gr1; gr1 = gr1->next) {
+               for (gr2 = gr1->next; NULL != gr2; gr2 = gr2->next) {
                        struct group *g1 = (struct group *)gr1->eptr;
                        struct group *g2 = (struct group *)gr2->eptr;
                        if (NULL != g1 &&
@@ -284,8 +285,9 @@ static int group_open_hook (void)
  * the modified first entry on success, or NULL on failure (with errno
  * set).
  */
-static struct commonio_entry *merge_group_entries (struct commonio_entry *gr1,
-                                                   struct commonio_entry *gr2)
+static /*@null@*/struct commonio_entry *merge_group_entries (
+       /*@null@*/struct commonio_entry *gr1,
+       /*@null@*/struct commonio_entry *gr2)
 {
        struct group *gptr1;
        struct group *gptr2;
@@ -332,6 +334,7 @@ static struct commonio_entry *merge_group_entries (struct commonio_entry *gr1,
        }
        new_members = (char **)malloc ( (members+1) * sizeof(char*) );
        if (NULL == new_members) {
+               free (new_line);
                errno = ENOMEM;
                return NULL;
        }
@@ -370,7 +373,7 @@ static int split_groups (unsigned int max_members)
 {
        struct commonio_entry *gr;
 
-       for (gr = group_db.head; gr; gr = gr->next) {
+       for (gr = group_db.head; NULL != gr; gr = gr->next) {
                struct group *gptr = (struct group *)gr->eptr;
                struct commonio_entry *new;
                struct group *new_gptr;
@@ -392,6 +395,7 @@ static int split_groups (unsigned int max_members)
                }
                new->eptr = group_dup(gr->eptr);
                if (NULL == new->eptr) {
+                       free (new);
                        errno = ENOMEM;
                        return 0;
                }
index fabfd237d356edcb0bbfbda807b6ca8b54930c83..851463bd2082a1c900042b5b8a3ada3f1b671a21 100644 (file)
@@ -54,18 +54,18 @@ struct sgrp {
 #include <stdio.h>             /* for FILE */
 
 #if __STDC__
-struct sgrp *getsgent (void);
-struct sgrp *getsgnam (const char *);
-struct sgrp *sgetsgent (const char *);
-struct sgrp *fgetsgent (FILE *);
+/*@observer@*//*@null@*/struct sgrp *getsgent (void);
+/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *);
+/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *);
+/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *);
 void setsgent (void);
 void endsgent (void);
 int putsgent (const struct sgrp *, FILE *);
 #else
-struct sgrp *getsgent ();
-struct sgrp *getsgnam ();
-struct sgrp *sgetsgent ();
-struct sgrp *fgetsgent ();
+/*@observer@*//*@null@*/struct sgrp *getsgent ();
+/*@observer@*//*@null@*/struct sgrp *getsgnam ();
+/*@observer@*//*@null@*/struct sgrp *sgetsgent ();
+/*@observer@*//*@null@*/struct sgrp *fgetsgent ();
 void setsgent ();
 void endsgent ();
 int putsgent ();
index ef7a74a5dd72c03914e875c4a930f6bd6fe47c16..cd0044bd096620d786a2309caaeee48267ac8c3d 100644 (file)
@@ -80,8 +80,8 @@ extern int chown_tree (const char *, uid_t, uid_t, gid_t, gid_t);
 extern void chown_tty (const struct passwd *);
 
 /* cleanup.c */
-typedef void (*cleanup_function) (void *arg);
-void add_cleanup (cleanup_function pcf, void *arg);
+typedef void (*cleanup_function) (/*@null@*/void *arg);
+void add_cleanup (cleanup_function pcf, /*@null@*/void *arg);
 void del_cleanup (cleanup_function pcf);
 void do_cleanups (void);
 
@@ -104,11 +104,11 @@ void cleanup_report_del_group_gshadow (void *group_name);
 void cleanup_report_mod_passwd (void *cleanup_info);
 void cleanup_report_mod_group (void *cleanup_info);
 void cleanup_report_mod_gshadow (void *cleanup_info);
-void cleanup_unlock_group (void *unused);
+void cleanup_unlock_group (/*@null@*/void *unused);
 #ifdef SHADOWGRP
-void cleanup_unlock_gshadow (void *unused);
+void cleanup_unlock_gshadow (/*@null@*/void *unused);
 #endif
-void cleanup_unlock_passwd (void *unused);
+void cleanup_unlock_passwd (/*@null@*/void *unused);
 
 /* console.c */
 extern bool console (const char *);
@@ -148,10 +148,10 @@ extern int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid);
 extern int get_gid (const char *gidstr, gid_t *gid);
 
 /* getgr_nam_gid.c */
-extern struct group *getgr_nam_gid (const char *grname);
+extern /*@null@*/struct group *getgr_nam_gid (const char *grname);
 
 /* getlong.c */
-extern int getlong (const char *numstr, long int *result);
+extern int getlong (const char *numstr, /*@out@*/long int *result);
 
 /* getrange */
 extern int getrange (char *range,
@@ -162,7 +162,7 @@ extern int getrange (char *range,
 extern int get_uid (const char *uidstr, uid_t *uid);
 
 /* fputsx.c */
-extern char *fgetsx (char *, int, FILE *);
+extern /*@null@*/char *fgetsx (/*@returned@*/ /*@out@*/char *, int, FILE *);
 extern int fputsx (const char *, FILE *);
 
 /* groupio.c */
@@ -199,11 +199,11 @@ extern void setup_limits (const struct passwd *);
 #endif
 
 /* list.c */
-extern char **add_list (char **, const char *);
-extern char **del_list (char **, const char *);
-extern char **dup_list (char *const *);
+extern /*@only@*/ /*@out@*/char **add_list (/*@returned@*/ /*@only@*/char **, const char *);
+extern /*@only@*/ /*@out@*/char **del_list (/*@returned@*/ /*@only@*/char **, const char *);
+extern /*@only@*/ /*@out@*/char **dup_list (char *const *);
 extern bool is_on_list (char *const *list, const char *member);
-extern char **comma_to_list (const char *);
+extern /*@only@*/char **comma_to_list (const char *);
 
 /* log.c */
 extern void dolastlog (struct lastlog *ll,
@@ -224,7 +224,7 @@ extern void mailcheck (void);
 extern void motd (void);
 
 /* myname.c */
-extern struct passwd *get_my_pwent (void);
+extern /*@null@*/struct passwd *get_my_pwent (void);
 
 /* obscure.c */
 #ifndef USE_PAM
@@ -266,7 +266,7 @@ extern int do_rlogin (const char *remote_host, char *name, size_t namelen,
                       char *term, size_t termlen);
 
 /* salt.c */
-extern char *crypt_make_salt (const char *meth, void *arg);
+extern /*@observer@*/const char *crypt_make_salt (/*@null@*/const char *meth, /*@null@*/void *arg);
 
 /* setugid.c */
 extern int setup_groups (const struct passwd *info);
@@ -367,15 +367,15 @@ extern /*@maynotreturn@*/ /*@only@*/char *xmalloc (size_t);
 extern /*@maynotreturn@*/ /*@only@*/char *xstrdup (const char *);
 
 /* xgetpwnam.c */
-extern struct passwd *xgetpwnam (const char *);
+extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *);
 /* xgetpwuid.c */
-extern struct passwd *xgetpwuid (uid_t);
+extern /*@null@*/ /*@only@*/struct passwd *xgetpwuid (uid_t);
 /* xgetgrnam.c */
-extern struct group *xgetgrnam (const char *);
+extern /*@null@*/ /*@only@*/struct group *xgetgrnam (const char *);
 /* xgetgrgid.c */
-extern struct group *xgetgrgid (gid_t);
+extern /*@null@*/ /*@only@*/struct group *xgetgrgid (gid_t);
 /* xgetspnam.c */
-extern struct spwd *xgetspnam(const char *);
+extern /*@null@*/ /*@only@*/struct spwd *xgetspnam(const char *);
 
 /* yesno.c */
 extern bool yes_or_no (bool read_only);
index 3b1d090bf22174c12b2169857bba6d52623a5a63..0489548a2417695cd3e5e85b5212d613ba2cdaf8 100644 (file)
@@ -42,7 +42,7 @@
 #include "commonio.h"
 #include "pwio.h"
 
-static void *passwd_dup (const void *ent)
+static /*@null@*/ /*@only@*/void *passwd_dup (const void *ent)
 {
        const struct passwd *pw = ent;
 
index d2482989067e41b45e2c4894185ea7c7e6874a5b..8437970cad4551b4d8b884bf4d3196c08992c8bd 100644 (file)
@@ -42,7 +42,7 @@
 #include "commonio.h"
 #include "sgroupio.h"
 
-struct sgrp *__sgr_dup (const struct sgrp *sgent)
+/*@null@*/ /*@only@*/struct sgrp *__sgr_dup (const struct sgrp *sgent)
 {
        struct sgrp *sg;
        int i;
@@ -90,7 +90,7 @@ struct sgrp *__sgr_dup (const struct sgrp *sgent)
        return sg;
 }
 
-static void *gshadow_dup (const void *ent)
+static /*@null@*/ /*@only@*/void *gshadow_dup (const void *ent)
 {
        const struct sgrp *sg = ent;
 
index 1ad1a2ddcac26db1b60c0e7beb31949397bf5d40..7921c9963026c4dd9fc7962b554d24bc12bb2500 100644 (file)
@@ -42,7 +42,7 @@
 #include "commonio.h"
 #include "shadowio.h"
 
-static void *shadow_dup (const void *ent)
+static /*@null@*/ /*@only@*/void *shadow_dup (const void *ent)
 {
        const struct spwd *sp = ent;
 
index 963c652da12c9bc01be19a57532eae39c985cb4e..732934c4225ece6ccaa27fbde733a932ed9c7790 100644 (file)
@@ -75,7 +75,7 @@ void do_cleanups (void)
 /*
  * add_cleanup - Add a cleanup_function to the cleanup_functions stack.
  */
-void add_cleanup (cleanup_function pcf, void *arg)
+void add_cleanup (cleanup_function pcf, /*@null@*/void *arg)
 {
        unsigned int i;
        assert (NULL != pcf);
index 5398a2d90277c6d05bfd5c6f7b8bbac8b6f6d66e..b0ca8c6ccf94e7ea9d26b0838292d94700829987 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 struct group *getgr_nam_gid (const char *grname)
+extern /*@null@*/struct group *getgr_nam_gid (const char *grname)
 {
        long long int gid;
        char *endptr;
index 1b243912b8ce1becfa5729807cc5503c8071180b..f9aa0b85cbe41a84bc0103420e43e49d39dc871b 100644 (file)
@@ -43,7 +43,7 @@
  *     name, and if not present it is added to a freshly allocated
  *     list of users.
  */
-char **add_list (char **list, const char *member)
+/*@only@*/ /*@out@*/char **add_list (/*@returned@*/ /*@only@*/char **list, const char *member)
 {
        int i;
        char **tmp;
@@ -93,7 +93,7 @@ char **add_list (char **list, const char *member)
  *     list of users.
  */
 
-char **del_list (char **list, const char *member)
+/*@only@*/ /*@out@*/char **del_list (/*@returned@*/ /*@only@*/char **list, const char *member)
 {
        int i, j;
        char **tmp;
@@ -141,7 +141,7 @@ char **del_list (char **list, const char *member)
        return tmp;
 }
 
-char **dup_list (char *const *list)
+/*@only@*/ /*@out@*/char **dup_list (char *const *list)
 {
        int i;
        char **tmp;
@@ -182,12 +182,13 @@ bool is_on_list (char *const *list, const char *member)
  * comma_to_list - convert comma-separated list to (char *) array
  */
 
-char **comma_to_list (const char *comma)
+/*@only@*/char **comma_to_list (const char *comma)
 {
        char *members;
        char **array;
        int i;
-       char *cp, *cp2;
+       const char *cp;
+       char *cp2;
 
        assert (NULL != comma);
 
index f22f5ab34e1272007aeb39eb2bfe60a6666d259b..309cfdbafe0eec1a23be86d1dbf29e50ab338455 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 1996 - 1997, Marek Michałkiewicz
  * Copyright (c) 2003 - 2005, Tomasz Kłoczko
- * Copyright (c) 2007 - 2008, Nicolas François
+ * Copyright (c) 2007 - 2009, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@
 #include "defines.h"
 #include <pwd.h>
 #include "prototypes.h"
-struct passwd *get_my_pwent (void)
+/*@null@*/struct passwd *get_my_pwent (void)
 {
        struct passwd *pw;
        const char *cp = getlogin ();
index d73646f6bd743b24e0085a6ecea508d9be5d8ee1..681262934de46ea492336abeb4cc7576bb4d321b 100644 (file)
 
 /* local function prototypes */
 static void seedRNG (void);
-static char *gensalt (size_t salt_size);
+static /*@observer@*/const char *gensalt (size_t salt_size);
 #ifdef USE_SHA_CRYPT
 static size_t SHA_salt_size (void);
-static const char *SHA_salt_rounds (int *prefered_rounds);
+static /*@observer@*/const char *SHA_salt_rounds (/*@null@*/int *prefered_rounds);
 #endif /* USE_SHA_CRYPT */
 
 #ifndef HAVE_L64A
-static char *l64a(long value)
+static /*@observer@*/char *l64a(long value)
 {
        static char buf[8];
        char *s = buf;
@@ -104,7 +104,7 @@ static size_t SHA_salt_size (void)
 /*
  * Return a salt prefix specifying the rounds number for the SHA crypt methods.
  */
-static const char *SHA_salt_rounds (int *prefered_rounds)
+static /*@observer@*/const char *SHA_salt_rounds (/*@null@*/int *prefered_rounds)
 {
        static char rounds_prefix[18];
        long rounds;
@@ -168,7 +168,7 @@ static const char *SHA_salt_rounds (int *prefered_rounds)
 #define MAX_SALT_SIZE 16
 #define MIN_SALT_SIZE 8
 
-static char *gensalt (size_t salt_size)
+static /*@observer@*/const char *gensalt (size_t salt_size)
 {
        static char salt[32];
 
@@ -202,7 +202,7 @@ static char *gensalt (size_t salt_size)
  *  * For the SHA256 and SHA512 method, this specifies the number of rounds
  *    (if not NULL).
  */
-char *crypt_make_salt (const char *meth, void *arg)
+/*@observer@*/const char *crypt_make_salt (/*@null@*/const char *meth, /*@null@*/void *arg)
 {
        /* Max result size for the SHA methods:
         *  +3          $5$
index db41a18e1ab58db1bca636c75a7705bc8f4fb3fc..6419aa908eb11021005f9730d99308d2cc0d22fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007 - 2008, Nicolas François
+ * Copyright (c) 2007 - 2009, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -64,7 +64,7 @@
 #define STRINGIZE(name) STRINGIZE1 (name)
 #define STRINGIZE1(name) #name
 
-LOOKUP_TYPE *XFUNCTION_NAME (ARG_TYPE ARG_NAME)
+/*@null@*/ /*@only@*/LOOKUP_TYPE *XFUNCTION_NAME (ARG_TYPE ARG_NAME)
 {
 #if HAVE_FUNCTION_R
        LOOKUP_TYPE *result=NULL;
index 88009b7dabf65cf6f593f74b3d21eae891145068..928a9d44723cb73dbb0c2e50d06ce4180f5d32c9 100644 (file)
@@ -123,11 +123,11 @@ extern char **environ;
 static void usage (void);
 static void setup_tty (void);
 static void process_flags (int argc, char *const *argv);
-static const char *get_failent_user (/*@returned@*/const char *user);
+static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *user);
 static void update_utmp (const char *username,
                          const char *tty,
                          const char *hostname,
-                         const struct utmp *utent);
+                         /*@null@*/const struct utmp *utent);
 
 #ifndef USE_PAM
 static struct faillog faillog;
@@ -194,13 +194,13 @@ static void setup_tty (void)
                /* Make sure the values were valid.
                 * getdef_num cannot validate this.
                 */
-               if (erasechar != termio.c_cc[VERASE]) {
+               if (erasechar != (int) termio.c_cc[VERASE]) {
                        fprintf (stderr,
                                 _("configuration error - cannot parse %s value: '%d'"),
                                 "ERASECHAR", erasechar);
                        exit (1);
                }
-               if (killchar != termio.c_cc[VKILL]) {
+               if (killchar != (int) termio.c_cc[VKILL]) {
                        fprintf (stderr,
                                 _("configuration error - cannot parse %s value: '%d'"),
                                 "KILLCHAR", killchar);
@@ -454,7 +454,7 @@ static void get_pam_user (char **ptr_pam_user)
  * It is quite common to mistyped the password for username, and passwords
  * should not be logged.
  */
-static const char *get_failent_user (/*@returned@*/const char *user)
+static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *user)
 {
        const char *failent_user = "UNKNOWN";
        bool log_unkfail_enab = getdef_bool("LOG_UNKFAIL_ENAB");
@@ -1000,7 +1000,7 @@ int main (int argc, char **argv)
                        failed = true;
                }
                if (   !failed
-                   && !login_access (username, *hostname ? hostname : tty)) {
+                   && !login_access (username, ('\0' != *hostname) ? hostname : tty)) {
                        SYSLOG ((LOG_WARN, "LOGIN '%s' REFUSED %s",
                                 username, fromhost));
                        failed = true;