mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 06:15:37 +00:00
Remove the NO_EXIT flag to log_error() and add a log_fatal() function
that exits and is marked no_return. Fixes false positives from static analyzers and is easier for humans to read too.
This commit is contained in:
@@ -120,9 +120,9 @@ mkdir_parents(char *path)
|
||||
*slash = '\0';
|
||||
if (stat(path, &sb) != 0) {
|
||||
if (mkdir(path, S_IRWXU) != 0)
|
||||
log_error(USE_ERRNO, _("unable to mkdir %s"), path);
|
||||
log_fatal(USE_ERRNO, _("unable to mkdir %s"), path);
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
log_error(0, _("%s: %s"), path, strerror(ENOTDIR));
|
||||
log_fatal(0, _("%s: %s"), path, strerror(ENOTDIR));
|
||||
}
|
||||
*slash = '/';
|
||||
}
|
||||
@@ -153,9 +153,9 @@ io_nextid(char *iolog_dir, char sessid[7])
|
||||
mkdir_parents(iolog_dir);
|
||||
if (stat(iolog_dir, &sb) != 0) {
|
||||
if (mkdir(iolog_dir, S_IRWXU) != 0)
|
||||
log_error(USE_ERRNO, _("unable to mkdir %s"), iolog_dir);
|
||||
log_fatal(USE_ERRNO, _("unable to mkdir %s"), iolog_dir);
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
log_error(0, _("%s exists but is not a directory (0%o)"),
|
||||
log_fatal(0, _("%s exists but is not a directory (0%o)"),
|
||||
iolog_dir, (unsigned int) sb.st_mode);
|
||||
}
|
||||
|
||||
@@ -165,21 +165,21 @@ io_nextid(char *iolog_dir, char sessid[7])
|
||||
len = snprintf(pathbuf, sizeof(pathbuf), "%s/seq", iolog_dir);
|
||||
if (len <= 0 || len >= sizeof(pathbuf)) {
|
||||
errno = ENAMETOOLONG;
|
||||
log_error(USE_ERRNO, "%s/seq", pathbuf);
|
||||
log_fatal(USE_ERRNO, "%s/seq", pathbuf);
|
||||
}
|
||||
fd = open(pathbuf, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
|
||||
if (fd == -1)
|
||||
log_error(USE_ERRNO, _("unable to open %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to open %s"), pathbuf);
|
||||
lock_file(fd, SUDO_LOCK);
|
||||
|
||||
/* Read seq number (base 36). */
|
||||
nread = read(fd, buf, sizeof(buf));
|
||||
if (nread != 0) {
|
||||
if (nread == -1)
|
||||
log_error(USE_ERRNO, _("unable to read %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to read %s"), pathbuf);
|
||||
id = strtoul(buf, &ep, 36);
|
||||
if (buf == ep || id >= SESSID_MAX)
|
||||
log_error(0, _("invalid sequence number %s"), pathbuf);
|
||||
log_fatal(0, _("invalid sequence number %s"), pathbuf);
|
||||
}
|
||||
id++;
|
||||
|
||||
@@ -199,7 +199,7 @@ io_nextid(char *iolog_dir, char sessid[7])
|
||||
|
||||
/* Rewind and overwrite old seq file. */
|
||||
if (lseek(fd, 0, SEEK_SET) == (off_t)-1 || write(fd, buf, 7) != 7)
|
||||
log_error(USE_ERRNO, _("unable to write to %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to write to %s"), pathbuf);
|
||||
close(fd);
|
||||
|
||||
debug_return;
|
||||
@@ -218,7 +218,7 @@ mkdir_iopath(const char *iolog_path, char *pathbuf, size_t pathsize)
|
||||
len = strlcpy(pathbuf, iolog_path, pathsize);
|
||||
if (len >= pathsize) {
|
||||
errno = ENAMETOOLONG;
|
||||
log_error(USE_ERRNO, "%s", iolog_path);
|
||||
log_fatal(USE_ERRNO, "%s", iolog_path);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -228,10 +228,10 @@ mkdir_iopath(const char *iolog_path, char *pathbuf, size_t pathsize)
|
||||
mkdir_parents(pathbuf);
|
||||
if (len >= 6 && strcmp(&pathbuf[len - 6], "XXXXXX") == 0) {
|
||||
if (mkdtemp(pathbuf) == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
} else {
|
||||
if (mkdir(pathbuf, S_IRWXU) != 0)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
}
|
||||
|
||||
debug_return_size_t(len);
|
||||
@@ -439,7 +439,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
debug_return_bool(true);
|
||||
|
||||
if (sigsetjmp(error_jmp, 1)) {
|
||||
/* called via error(), errorx() or log_error() */
|
||||
/* called via error(), errorx() or log_fatal() */
|
||||
rval = -1;
|
||||
goto done;
|
||||
}
|
||||
@@ -496,18 +496,18 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
*/
|
||||
io_logfile = open_io_fd(pathbuf, len, "/log", false);
|
||||
if (io_logfile == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
|
||||
io_fds[IOFD_TIMING].v = open_io_fd(pathbuf, len, "/timing",
|
||||
iolog_compress);
|
||||
if (io_fds[IOFD_TIMING].v == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
|
||||
if (details.iolog_ttyin) {
|
||||
io_fds[IOFD_TTYIN].v = open_io_fd(pathbuf, len, "/ttyin",
|
||||
iolog_compress);
|
||||
if (io_fds[IOFD_TTYIN].v == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
} else {
|
||||
sudoers_io.log_ttyin = NULL;
|
||||
}
|
||||
@@ -515,7 +515,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
io_fds[IOFD_STDIN].v = open_io_fd(pathbuf, len, "/stdin",
|
||||
iolog_compress);
|
||||
if (io_fds[IOFD_STDIN].v == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
} else {
|
||||
sudoers_io.log_stdin = NULL;
|
||||
}
|
||||
@@ -523,7 +523,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
io_fds[IOFD_TTYOUT].v = open_io_fd(pathbuf, len, "/ttyout",
|
||||
iolog_compress);
|
||||
if (io_fds[IOFD_TTYOUT].v == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
} else {
|
||||
sudoers_io.log_ttyout = NULL;
|
||||
}
|
||||
@@ -531,7 +531,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
io_fds[IOFD_STDOUT].v = open_io_fd(pathbuf, len, "/stdout",
|
||||
iolog_compress);
|
||||
if (io_fds[IOFD_STDOUT].v == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
} else {
|
||||
sudoers_io.log_stdout = NULL;
|
||||
}
|
||||
@@ -539,7 +539,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
io_fds[IOFD_STDERR].v = open_io_fd(pathbuf, len, "/stderr",
|
||||
iolog_compress);
|
||||
if (io_fds[IOFD_STDERR].v == NULL)
|
||||
log_error(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
log_fatal(USE_ERRNO, _("unable to create %s"), pathbuf);
|
||||
} else {
|
||||
sudoers_io.log_stderr = NULL;
|
||||
}
|
||||
@@ -581,7 +581,7 @@ sudoers_io_close(int exit_status, int error)
|
||||
debug_decl(sudoers_io_close, SUDO_DEBUG_PLUGIN)
|
||||
|
||||
if (sigsetjmp(error_jmp, 1)) {
|
||||
/* called via error(), errorx() or log_error() */
|
||||
/* called via error(), errorx() or log_fatal() */
|
||||
debug_return;
|
||||
}
|
||||
|
||||
@@ -604,7 +604,7 @@ sudoers_io_version(int verbose)
|
||||
debug_decl(sudoers_io_version, SUDO_DEBUG_PLUGIN)
|
||||
|
||||
if (sigsetjmp(error_jmp, 1)) {
|
||||
/* called via error(), errorx() or log_error() */
|
||||
/* called via error(), errorx() or log_fatal() */
|
||||
debug_return_bool(-1);
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
if (sigsetjmp(error_jmp, 1)) {
|
||||
/* called via error(), errorx() or log_error() */
|
||||
/* called via error(), errorx() or log_fatal() */
|
||||
debug_return_bool(-1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user