From 73df45e6f22ed3ccec8ba0e36487f6e8371440ac Mon Sep 17 00:00:00 2001 From: mmaslano Date: Fri, 17 Aug 2007 15:12:59 +0200 Subject: [PATCH] The return value were added because of too many warning messages from compiler. Also the variables were initialized. --- crontab.c | 22 ++++++++++++++-------- do_command.c | 19 ++++++++++++++++--- env.c | 4 ++-- misc.c | 26 ++++++++++++++++++++------ pw_dup.c | 2 +- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/crontab.c b/crontab.c index b8c5482..a96f8c8 100644 --- a/crontab.c +++ b/crontab.c @@ -283,14 +283,14 @@ list_cmd(void) { static void delete_cmd(void) { - char n[MAX_FNAME]; + char n[MAX_FNAME]=""; if( PromptOnDelete == 1 ) { printf("crontab: really delete %s's crontab? ", User); fflush(stdout); - fgets(n, MAX_FNAME-1, stdin); - if((n[0] != 'Y') && (n[0] != 'y')) - exit(0); + if( (fgets(n, MAX_FNAME-1, stdin)==0L) + ||((n[0] != 'Y') && (n[0] != 'y')) + ) exit(0); } log_it(RealUser, Pid, "DELETE", User); @@ -534,7 +534,8 @@ edit_cmd(void) { printf("Do you want to retry the same edit? "); fflush(stdout); q[0] = '\0'; - (void) fgets(q, sizeof q, stdin); + if( fgets(q, sizeof q, stdin) == 0L ) + continue; switch (q[0]) { case 'y': case 'Y': @@ -575,7 +576,6 @@ replace_cmd(void) { int error = 0; entry *e; uid_t file_owner; - time_t now = time(NULL); char **envp = env_init(); if (envp == NULL) { @@ -618,9 +618,15 @@ replace_cmd(void) { Set_LineNum(1) while (EOF != (ch = get_char(NewCrontab))) putc(ch, tmp); - ftruncate(fileno(tmp), ftell(tmp)); /* XXX redundant with "w+"? */ + if( ftruncate(fileno(tmp), ftell(tmp)) == -1 ) + { + fprintf(stderr, "%s: error while writing new crontab to %s\n", + ProgramName, TempFilename); + fclose(tmp); + error = -2; + goto done; + } fflush(tmp); rewind(tmp); - if (ferror(tmp)) { fprintf(stderr, "%s: error while writing new crontab to %s\n", ProgramName, TempFilename); diff --git a/do_command.c b/do_command.c index e49c114..ee17b44 100644 --- a/do_command.c +++ b/do_command.c @@ -137,8 +137,17 @@ child_process(entry *e, user *u) { /* create some pipes to talk to our future child */ - pipe(stdin_pipe); /* child's stdin */ - pipe(stdout_pipe); /* child's stdout */ + if( pipe(stdin_pipe) == -1 ) /* child's stdin */ + { + log_it("CRON", getpid(), "pipe() failed:", strerror(errno)); + return; + } + + if( pipe(stdout_pipe) == -1 ) /* child's stdout */ + { + log_it("CRON", getpid(), "pipe() failed:", strerror(errno)); + return; + } /* since we are a forked process, we can diddle the command string * we were passed -- nobody else is going to use it again, right? @@ -318,7 +327,11 @@ child_process(entry *e, user *u) { setuid(e->pwd->pw_uid); /* we aren't root after this... */ #endif /* LOGIN_CAP */ - chdir(env_get("HOME", e->envp)); + if ( chdir(env_get("HOME", e->envp)) == -1 ) + { + log_it("CRON", getpid(), "chdir(HOME) failed:", strerror(errno)); + _exit(ERROR_EXIT); + } /* * Exec the command. diff --git a/env.c b/env.c index ed82f6b..a410252 100644 --- a/env.c +++ b/env.c @@ -48,8 +48,8 @@ env_copy(char **envp) { int count, i, save_errno; char **p; - for (count = 0; envp[count] != NULL; count++) - NULL; + for (count = 0; envp[count] != NULL; count++); + p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */ if (p != NULL) { for (i = 0; i < count; i++) diff --git a/misc.c b/misc.c index b875673..a4ce5e5 100644 --- a/misc.c +++ b/misc.c @@ -153,7 +153,7 @@ set_debug_flags(const char *flags) { for (test = DebugFlagNames, mask = 1; *test != NULL && strcmp_until(*test, pc, ','); test++, mask <<= 1) - NULL; + ; if (!*test) { fprintf(stderr, @@ -255,9 +255,17 @@ set_cron_cwd(void) { } if (grp != NULL) { if (sb.st_gid != grp->gr_gid) - chown(SPOOL_DIR, -1, grp->gr_gid); + if( chown(SPOOL_DIR, -1, grp->gr_gid) == -1 ) + { + fprintf(stderr,"chdir %s failed: %s\n", SPOOL_DIR, strerror(errno)); + exit(ERROR_EXIT); + } if (sb.st_mode != 01730) - chmod(SPOOL_DIR, 01730); + if( chmod(SPOOL_DIR, 01730) == -1 ) + { + fprintf(stderr,"chmod 01730 %s failed: %s\n", SPOOL_DIR, strerror(errno)); + exit(ERROR_EXIT); + } } } @@ -275,7 +283,7 @@ acquire_daemonlock(int closeflag) { const char *pidfile; char *ep; long otherpid=-1; - ssize_t num; + ssize_t num, len; if (closeflag) { /* close stashed fd for child so we don't leak it. */ @@ -324,8 +332,14 @@ acquire_daemonlock(int closeflag) { sprintf(buf, "%ld\n", (long)getpid()); (void) lseek(fd, (off_t)0, SEEK_SET); - num = write(fd, buf, strlen(buf)); - (void) ftruncate(fd, num); + len = strlen(buf); + if( (num = write(fd, buf, len)) != len ) + log_it("CRON", getpid(), "write() failed:", strerror(errno)); + else + { + if( ftruncate(fd, num) == -1 ) + log_it("CRON", getpid(), "ftruncate() failed:", strerror(errno)); + } /* abandon fd even though the file is open. we need to keep * it open and locked, but we don't need the handles elsewhere. diff --git a/pw_dup.c b/pw_dup.c index c2a3c38..58b851d 100644 --- a/pw_dup.c +++ b/pw_dup.c @@ -47,7 +47,7 @@ static char rcsid[] = "$Id: pw_dup.c,v 1.2 2004/01/23 18:56:43 vixie Exp $"; struct passwd * pw_dup(const struct passwd *pw) { char *cp; - size_t nsize=0, psize=0, csize=0, gsize=0, dsize=0, ssize=0, total=0; + size_t nsize=0, psize=0, gsize=0, dsize=0, ssize=0, total=0; struct passwd *newpw; /* Allocate in one big chunk for easy freeing */ -- 2.40.0