]> granicus.if.org Git - sudo/commitdiff
Quiet gcc warnings on glibc systems that use warn_unused_result for
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 3 Aug 2010 15:17:56 +0000 (11:17 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 3 Aug 2010 15:17:56 +0000 (11:17 -0400)
write(2) and others.

plugins/sudoers/check.c
plugins/sudoers/logging.c
plugins/sudoers/sudoreplay.c
plugins/sudoers/visudo.c
src/exec_pty.c
src/get_pty.c
src/tgetpass.c

index bafcc5e55c5bad411efba610ec974c461d2c6e16..a644080f39063c7d337f6e9aa404bedca4e93a10 100644 (file)
@@ -216,7 +216,8 @@ update_timestamp(char *timestampdir, char *timestampfile)
            log_error(NO_EXIT|USE_ERRNO, "Can't open %s", timestampfile);
        else {
            lock_file(fd, SUDO_LOCK);
-           write(fd, &tty_info, sizeof(tty_info));
+           if (write(fd, &tty_info, sizeof(tty_info)) != sizeof(tty_info))
+               log_error(NO_EXIT|USE_ERRNO, "Can't write %s", timestampfile);
            close(fd);
        }
     } else {
index 217ac77c64811641d886a7a73ceda1d09752fc9c..8e2ea100449505b09910609333035fa5eaddc16f 100644 (file)
@@ -452,7 +452,8 @@ send_mail(const char *fmt, ...)
     /* Daemonize - disassociate from session/tty. */
     if (setsid() == -1)
       warning("setsid");
-    (void) chdir("/");
+    if (chdir("/") == -1)
+      warning("chdir(/)");
     if ((fd = open(_PATH_DEVNULL, O_RDWR, 0644)) != -1) {
        (void) dup2(fd, STDIN_FILENO);
        (void) dup2(fd, STDOUT_FILENO);
index bf416a6011ed55ce9aa9de30b97993c33dca89d2..1f7e3d4aafb74e57f497424b83294085139babff 100644 (file)
@@ -312,9 +312,12 @@ main(int argc, char *argv[])
        error(1, "unable to open %s", path);
     cp = NULL;
     len = 0;
-    getline(&cp, &len, lfile); /* log */
-    getline(&cp, &len, lfile); /* cwd */
-    getline(&cp, &len, lfile); /* command */
+    /* Pull out command (third line). */
+    if (getline(&cp, &len, lfile) == -1 ||
+       getline(&cp, &len, lfile) == -1 ||
+       getline(&cp, &len, lfile) == -1) {
+       error(1, "invalid log file %s", path);
+    }
     printf("Replaying sudo session: %s", cp);
     free(cp);
     fclose(lfile);
index d20a0dec4e5b0cd4ec10dd5aa8189f3c06915064..03ba088c52f7a3783679fb3ed4eb9926abc6fac5 100644 (file)
@@ -290,7 +290,8 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno)
            /* Add missing newline at EOF if needed. */
            if (nread > 0 && buf[nread - 1] != '\n') {
                buf[0] = '\n';
-               write(tfd, buf, 1);
+               if (write(tfd, buf, 1) != 1)
+                   error(1, "write error");
            }
        }
        (void) close(tfd);
@@ -483,8 +484,14 @@ install_sudoers(struct sudoersfile *sp, int oldperms)
        if (stat(sp->path, &sb) == -1)
 #endif
            error(1, "can't stat %s", sp->path);
-       (void) chown(sp->tpath, sb.st_uid, sb.st_gid);
-       (void) chmod(sp->tpath, sb.st_mode & 0777);
+       if (chown(sp->tpath, sb.st_uid, sb.st_gid) != 0) {
+           warning("unable to set (uid, gid) of %s to (%d, %d)",
+               sp->tpath, sb.st_uid, sb.st_gid);
+       }
+       if (chmod(sp->tpath, sb.st_mode & 0777) != 0) {
+           warning("unable to change mode of %s to 0%o", sp->tpath,
+               (sb.st_mode & 0777));
+       }
     } else {
        if (chown(sp->tpath, SUDOERS_UID, SUDOERS_GID) != 0) {
            warning("unable to set (uid, gid) of %s to (%d, %d)",
@@ -1143,8 +1150,9 @@ quit(int signo)
 {
     cleanup(signo);
 #define        emsg     " exiting due to signal.\n"
-    write(STDERR_FILENO, getprogname(), strlen(getprogname()));
-    write(STDERR_FILENO, emsg, sizeof(emsg) - 1);
+    if (write(STDERR_FILENO, getprogname(), strlen(getprogname())) == -1 ||
+       write(STDERR_FILENO, emsg, sizeof(emsg) - 1) == -1)
+       /* shut up glibc */;
     _exit(signo);
 }
 
index 165e3dc33fbb3ea93fc80c02fbdf3696eccd13cc..0e8adc3213e14de0d1b8f674458dfec3ab78feb5 100644 (file)
@@ -639,10 +639,14 @@ pty_close(struct command_status *cstat)
            const char *reason = strsignal(signo);
            n = io_fds[SFD_USERTTY] != -1 ?
                io_fds[SFD_USERTTY] : STDOUT_FILENO;
-           write(n, reason, strlen(reason));
-           if (WCOREDUMP(cstat->val))
-               write(n, " (core dumped)", 14);
-           write(n, "\n", 1);
+           if (write(n, reason, strlen(reason)) != -1) {
+               if (WCOREDUMP(cstat->val)) {
+                   if (write(n, " (core dumped)", 14) == -1)
+                       /* shut up glibc */;
+               }
+               if (write(n, "\n", 1) == -1)
+                   /* shut up glibc */;
+           }
        }
     }
 }
@@ -875,7 +879,8 @@ exec_monitor(struct command_details *details, char *argv[], char *envp[],
        exec_pty(details, argv, envp);
        cstat.type = CMD_ERRNO;
        cstat.val = errno;
-       write(errpipe[1], &cstat, sizeof(cstat));
+       if (write(errpipe[1], &cstat, sizeof(cstat)) == -1)
+           /* shut up glibc */;
        _exit(1);
     }
     close(errpipe[1]);
index 15d653c1be467973634fee8979f1f74dd6308a99..72873a0fb90e1c770e9baa81f486011f1c086f61 100644 (file)
@@ -67,7 +67,8 @@ get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid)
 
     if (openpty(master, slave, name, NULL, NULL) != 0)
        return(0);
-    (void) chown(name, ttyuid, ttygid);
+    if (chown(name, ttyuid, ttygid) != 0)
+       return(0);
     return(1);
 }
 
index a0c6578fa7fd73f0423b7b29380f50a60219a795..ad88086b8e2c87ff312410193b34c856bb78190f 100644 (file)
@@ -150,8 +150,10 @@ restart:
     sa.sa_handler = SIG_IGN;
     (void) sigaction(SIGPIPE, &sa, &savepipe);
 
-    if (prompt)
-       (void) write(output, prompt, strlen(prompt));
+    if (prompt) {
+       if (write(output, prompt, strlen(prompt)) == -1)
+           goto restore;
+    }
 
     if (timeout > 0)
        alarm(timeout);
@@ -159,9 +161,12 @@ restart:
     alarm(0);
     save_errno = errno;
 
-    if (neednl || pass == NULL)
-       (void) write(output, "\n", 1);
+    if (neednl || pass == NULL) {
+       if (write(output, "\n", 1) == -1)
+           goto restore;
+    }
 
+restore:
     /* Restore old tty settings and signals. */
     if (!ISSET(flags, TGP_ECHO))
        term_restore(input, 1);
@@ -277,20 +282,23 @@ getln(int fd, char *buf, size_t bufsiz, int feedback)
        if (feedback) {
            if (c == term_kill) {
                while (cp > buf) {
-                   (void) write(fd, "\b \b", 3);
+                   if (write(fd, "\b \b", 3) == -1)
+                       break;
                    --cp;
                }
                left = bufsiz;
                continue;
            } else if (c == term_erase) {
                if (cp > buf) {
-                   (void) write(fd, "\b \b", 3);
+                   if (write(fd, "\b \b", 3) == -1)
+                       break;
                    --cp;
                    left++;
                }
                continue;
            }
-           (void) write(fd, "*", 1);
+           if (write(fd, "*", 1) == -1)
+               /* shut up glibc */;
        }
        *cp++ = c;
     }
@@ -298,7 +306,8 @@ getln(int fd, char *buf, size_t bufsiz, int feedback)
     if (feedback) {
        /* erase stars */
        while (cp > buf) {
-           (void) write(fd, "\b \b", 3);
+           if (write(fd, "\b \b", 3) == -1)
+               break;
            --cp;
        }
     }