From: Todd C. Miller Date: Tue, 3 Aug 2010 15:18:07 +0000 (-0400) Subject: Quiet gcc warnings on glibc systems that use warn_unused_result for X-Git-Tag: SUDO_1_7_5~212 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8424430211070748e7de0900cd4cba76e0a47b3;p=sudo Quiet gcc warnings on glibc systems that use warn_unused_result for write(2) and others. --HG-- branch : 1.7 --- diff --git a/check.c b/check.c index 8b7834a03..e35246f9d 100644 --- a/check.c +++ b/check.c @@ -219,7 +219,8 @@ update_timestamp(timestampdir, 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 { diff --git a/exec_pty.c b/exec_pty.c index 191e0e3ff..57e950c5d 100644 --- a/exec_pty.c +++ b/exec_pty.c @@ -525,10 +525,14 @@ pty_close(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 */; + } } } } @@ -763,7 +767,8 @@ exec_monitor(path, argv, envp, backchannel, rbac) exec_pty(path, argv, envp, rbac); 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]); diff --git a/get_pty.c b/get_pty.c index 7bc035518..5eb653fae 100644 --- a/get_pty.c +++ b/get_pty.c @@ -72,7 +72,8 @@ get_pty(master, slave, name, namesz, 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); } diff --git a/logging.c b/logging.c index 2b329683f..133939175 100644 --- a/logging.c +++ b/logging.c @@ -479,7 +479,8 @@ send_mail(fmt, va_alist) /* 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); diff --git a/sudoreplay.c b/sudoreplay.c index 58b8639d7..98cde87aa 100644 --- a/sudoreplay.c +++ b/sudoreplay.c @@ -316,9 +316,12 @@ main(argc, 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); diff --git a/tgetpass.c b/tgetpass.c index 8127eab1e..44bb062f5 100644 --- a/tgetpass.c +++ b/tgetpass.c @@ -127,8 +127,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); @@ -136,9 +138,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); @@ -252,20 +257,23 @@ getln(fd, buf, bufsiz, 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; } @@ -273,7 +281,8 @@ getln(fd, buf, bufsiz, feedback) if (feedback) { /* erase stars */ while (cp > buf) { - (void) write(fd, "\b \b", 3); + if (write(fd, "\b \b", 3) == -1) + break; --cp; } } diff --git a/visudo.c b/visudo.c index ab8d58744..e2ca61a11 100644 --- a/visudo.c +++ b/visudo.c @@ -293,7 +293,8 @@ edit_sudoers(sp, editor, args, 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); @@ -490,8 +491,14 @@ install_sudoers(sp, 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)", @@ -1168,8 +1175,9 @@ quit(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); }