From af8ff8c1ca9e7fe6cba4d0aa8238097242e2ab01 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Thu, 23 Apr 2009 20:37:00 +0000 Subject: [PATCH] * src/newgrp.c: Added splint annotations. * src/newgrp.c: audit_buf is only used in newgrp. Make it static. * src/newgrp.c: Ignore the return value of fputs(). * src/newgrp.c: Use exit(EXIT_FAILURE) instead of exit(1). --- ChangeLog | 7 +++++++ src/newgrp.c | 38 +++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 764cc2cb..fd4ae723 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-04-22 Nicolas François + + * src/newgrp.c: Added splint annotations. + * src/newgrp.c: audit_buf is only used in newgrp. Make it static. + * src/newgrp.c: Ignore the return value of fputs(). + * src/newgrp.c: Use exit(EXIT_FAILURE) instead of exit(1). + 2009-04-22 Nicolas François * libmisc/pwdcheck.c (passwd_check): The progname is not used. diff --git a/src/newgrp.c b/src/newgrp.c index 71b704b7..51c2045d 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -53,13 +53,13 @@ extern char **environ; #ifdef HAVE_SETGROUPS static int ngroups; -static GETGROUPS_T *grouplist; +static /*@null@*/ /*@only@*/GETGROUPS_T *grouplist; #endif static bool is_newgrp; #ifdef WITH_AUDIT -char audit_buf[80]; +static char audit_buf[80]; #endif /* local function prototypes */ @@ -75,9 +75,9 @@ static void syslog_sg (const char *name, const char *group); static void usage (void) { if (is_newgrp) { - fputs (_("Usage: newgrp [-] [group]\n"), stderr); + (void) fputs (_("Usage: newgrp [-] [group]\n"), stderr); } else { - fputs (_("Usage: sg group [[-c] command]\n"), stderr); + (void) fputs (_("Usage: sg group [[-c] command]\n"), stderr); } } @@ -85,7 +85,7 @@ static void usage (void) * find_matching_group - search all groups of a given group id for * membership of a given username */ -static struct group *find_matching_group (const char *name, gid_t gid) +static /*@null@*/struct group *find_matching_group (const char *name, gid_t gid) { struct group *gr; char **look; @@ -195,8 +195,8 @@ static void check_perms (const struct group *grp, SYSLOG ((LOG_INFO, "Invalid password for group '%s' from '%s'", groupname, pwd->pw_name)); - sleep (1); - fputs (_("Invalid password.\n"), stderr); + (void) sleep (1); + (void) fputs (_("Invalid password.\n"), stderr); goto failure; } #ifdef WITH_AUDIT @@ -229,7 +229,7 @@ failure: (unsigned int) getuid (), 0); } #endif - exit (1); + exit (EXIT_FAILURE); } #ifdef USE_SYSLOG @@ -308,7 +308,7 @@ static void syslog_sg (const char *name, const char *group) (unsigned int) getuid (), 0); } #endif - exit (1); + exit (EXIT_FAILURE); } else if (child != 0) { /* parent - wait for child to finish, then log session close */ int cst = 0; @@ -345,7 +345,7 @@ static void syslog_sg (const char *name, const char *group) (unsigned long) gid, name)); } closelog (); - exit (0); + exit (EXIT_SUCCESS); } /* child - restore signals to their default state */ @@ -376,7 +376,7 @@ int main (int argc, char **argv) char *command = NULL; char **envp = environ; struct passwd *pwd; - struct group *grp; + /*@null@*/struct group *grp; #ifdef SHADOWGRP struct sgrp *sgrp; @@ -433,7 +433,7 @@ int main (int argc, char **argv) SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", (unsigned long) getuid ())); closelog (); - exit (1); + exit (EXIT_FAILURE); } name = pwd->pw_name; @@ -473,7 +473,7 @@ int main (int argc, char **argv) } else { usage (); closelog (); - exit (1); + exit (EXIT_FAILURE); } if (argc > 0) { @@ -555,7 +555,7 @@ int main (int argc, char **argv) (unsigned int) getuid (), 0); } #endif - exit (1); + exit (EXIT_FAILURE); } #endif /* HAVE_SETGROUPS */ @@ -661,7 +661,7 @@ int main (int argc, char **argv) } if (i == ngroups) { if (ngroups >= sysconf (_SC_NGROUPS_MAX)) { - fputs (_("too many groups\n"), stderr); + (void) fputs (_("too many groups\n"), stderr); } else { grouplist[ngroups++] = gid; if (setgroups (ngroups, grouplist) != 0) { @@ -685,7 +685,7 @@ int main (int argc, char **argv) audit_buf, NULL, (unsigned int) getuid (), 0); #endif - exit (1); + exit (EXIT_FAILURE); } if (setuid (getuid ()) != 0) { @@ -697,7 +697,7 @@ int main (int argc, char **argv) audit_buf, NULL, (unsigned int) getuid (), 0); #endif - exit (1); + exit (EXIT_FAILURE); } /* @@ -795,7 +795,7 @@ int main (int argc, char **argv) */ err = shell (prog, initflag ? (char *) 0 : cp, newenvp); exit (err == ENOENT ? E_CMD_NOTFOUND : E_CMD_NOEXEC); - /* NOTREACHED */ + /* @notreached@ */ failure: /* @@ -822,6 +822,6 @@ int main (int argc, char **argv) (unsigned int) getuid (), 0); } #endif - exit (1); + exit (EXIT_FAILURE); } -- 2.40.0