write(2) and others.
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 {
/* 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);
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);
/* 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);
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)",
{
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);
}
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 */;
+ }
}
}
}
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]);
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);
}
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);
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);
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;
}
if (feedback) {
/* erase stars */
while (cp > buf) {
- (void) write(fd, "\b \b", 3);
+ if (write(fd, "\b \b", 3) == -1)
+ break;
--cp;
}
}