sudo frontend: silence most -Wconversion warnings.

This commit is contained in:
Todd C. Miller
2023-07-07 15:07:04 -06:00
parent 0c85f10c80
commit 32f4b98f6b
23 changed files with 185 additions and 171 deletions

View File

@@ -65,7 +65,7 @@ static sudo_conv_t sudo_conv;
static sudo_printf_t sudo_log; static sudo_printf_t sudo_log;
static FILE *input, *output; static FILE *input, *output;
static uid_t runas_uid = ROOT_UID; static uid_t runas_uid = ROOT_UID;
static gid_t runas_gid = -1; static gid_t runas_gid = (gid_t)-1;
static int use_sudoedit = false; static int use_sudoedit = false;
/* /*
@@ -286,7 +286,7 @@ find_editor(int nfiles, char * const files[], char **argv_out[])
} }
if (editor_path != editor) if (editor_path != editor)
free(editor); free(editor);
nargv = malloc((nargc + 1 + nfiles + 1) * sizeof(char *)); nargv = reallocarray(NULL, (size_t)(nargc + 1 + nfiles + 1), sizeof(char *));
if (nargv == NULL) { if (nargv == NULL) {
sudo_log(SUDO_CONV_ERROR_MSG, "unable to allocate memory\n"); sudo_log(SUDO_CONV_ERROR_MSG, "unable to allocate memory\n");
free(editor_path); free(editor_path);

View File

@@ -199,7 +199,7 @@ sudo_conversation_printf(int msg_type, const char *fmt, ...)
len = vfprintf(ttyfp ? ttyfp : fp, fmt, ap); len = vfprintf(ttyfp ? ttyfp : fp, fmt, ap);
va_end(ap); va_end(ap);
if (len >= 0 && crnl != NULL) { if (len >= 0 && crnl != NULL) {
len += fwrite(crnl, 1, 2, ttyfp ? ttyfp : fp); len += (int)fwrite(crnl, 1, 2, ttyfp ? ttyfp : fp);
} }
break; break;
default: default:

View File

@@ -54,10 +54,10 @@ sudo_extend_file(int fd, const char *name, off_t new_size)
__func__, name, (long long)old_size, (long long)new_size); __func__, name, (long long)old_size, (long long)new_size);
for (size = old_size; size < new_size; size += nwritten) { for (size = old_size; size < new_size; size += nwritten) {
size_t len = new_size - size; off_t len = new_size - size;
if (len > sizeof(zeroes)) if (len > ssizeof(zeroes))
len = sizeof(zeroes); len = ssizeof(zeroes);
nwritten = write(fd, zeroes, len); nwritten = write(fd, zeroes, (size_t)len);
if (nwritten == -1) { if (nwritten == -1) {
int serrno = errno; int serrno = errno;
if (ftruncate(fd, old_size) == -1) { if (ftruncate(fd, old_size) == -1) {
@@ -110,7 +110,7 @@ sudo_copy_file(const char *src, int src_fd, off_t src_len, const char *dst,
while ((nread = read(src_fd, buf, sizeof(buf))) > 0) { while ((nread = read(src_fd, buf, sizeof(buf))) > 0) {
ssize_t off = 0; ssize_t off = 0;
do { do {
nwritten = write(dst_fd, buf + off, nread - off); nwritten = write(dst_fd, buf + off, (size_t)(nread - off));
if (nwritten == -1) if (nwritten == -1)
goto write_error; goto write_error;
off += nwritten; off += nwritten;

View File

@@ -96,7 +96,7 @@ rpl_putenv(PUTENV_CONST char *string)
} }
/* Look for existing entry. */ /* Look for existing entry. */
len = (equal - string) + 1; len = (size_t)(equal - string) + 1;
for (ep = environ; *ep != NULL; ep++) { for (ep = environ; *ep != NULL; ep++) {
if (strncmp(string, *ep, len) == 0) { if (strncmp(string, *ep, len) == 0) {
*ep = (char *)string; *ep = (char *)string;

View File

@@ -133,7 +133,7 @@ exec_setup(struct command_details *details, int intercept_fd, int errfd)
#endif #endif
#ifdef HAVE_LOGIN_CAP_H #ifdef HAVE_LOGIN_CAP_H
if (details->login_class) { if (details->login_class) {
int flags; unsigned int flags;
login_cap_t *lc; login_cap_t *lc;
/* /*

View File

@@ -123,11 +123,11 @@ sudo_execve(int fd, const char *path, char *const argv[], char *envp[],
for (argc = 0; argv[argc] != NULL; argc++) for (argc = 0; argv[argc] != NULL; argc++)
continue; continue;
nargv = reallocarray(NULL, argc + 2, sizeof(char *)); nargv = reallocarray(NULL, (size_t)argc + 2, sizeof(char *));
if (nargv != NULL) { if (nargv != NULL) {
nargv[0] = "sh"; nargv[0] = "sh";
nargv[1] = path; nargv[1] = path;
memcpy(nargv + 2, argv + 1, argc * sizeof(char *)); memcpy(nargv + 2, argv + 1, (size_t)argc * sizeof(char *));
execve(_PATH_SUDO_BSHELL, (char **)nargv, envp); execve(_PATH_SUDO_BSHELL, (char **)nargv, envp);
free(nargv); free(nargv);
} }

View File

@@ -1,7 +1,7 @@
/* /*
* SPDX-License-Identifier: ISC * SPDX-License-Identifier: ISC
* *
* Copyright (c) 2021-2022 Todd C. Miller <Todd.Miller@sudo.ws> * Copyright (c) 2021-2023 Todd C. Miller <Todd.Miller@sudo.ws>
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -37,6 +37,7 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h>
#include "sudo.h" #include "sudo.h"
#include "sudo_exec.h" #include "sudo_exec.h"
@@ -374,7 +375,8 @@ intercept_check_policy(const char *command, int argc, char **argv, int envc,
char **command_info_copy = NULL; char **command_info_copy = NULL;
char **user_env_out = NULL; char **user_env_out = NULL;
char **run_argv = NULL; char **run_argv = NULL;
int i, rc, saved_dir = -1; int rc, saved_dir = -1;
size_t i;
bool ret = true; bool ret = true;
struct stat sb; struct stat sb;
debug_decl(intercept_check_policy, SUDO_DEBUG_EXEC); debug_decl(intercept_check_policy, SUDO_DEBUG_EXEC);
@@ -470,11 +472,11 @@ intercept_check_policy(const char *command, int argc, char **argv, int envc,
"run_command: %s", closure->command); "run_command: %s", closure->command);
for (i = 0; command_info[i] != NULL; i++) { for (i = 0; command_info[i] != NULL; i++) {
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
"command_info[%d]: %s", i, command_info[i]); "command_info[%zu]: %s", i, command_info[i]);
} }
for (i = 0; run_argv[i] != NULL; i++) { for (i = 0; run_argv[i] != NULL; i++) {
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
"run_argv[%d]: %s", i, run_argv[i]); "run_argv[%zu]: %s", i, run_argv[i]);
} }
} }
@@ -492,10 +494,10 @@ intercept_check_policy(const char *command, int argc, char **argv, int envc,
closure->run_argv[i] = NULL; closure->run_argv[i] = NULL;
/* Make a copy of envp, which may not be NULL-terminated. */ /* Make a copy of envp, which may not be NULL-terminated. */
closure->run_envp = reallocarray(NULL, envc + 1, sizeof(char *)); closure->run_envp = reallocarray(NULL, (size_t)envc + 1, sizeof(char *));
if (closure->run_envp == NULL) if (closure->run_envp == NULL)
goto oom; goto oom;
for (i = 0; i < envc; i++) { for (i = 0; i < (size_t)envc; i++) {
closure->run_envp[i] = strdup(envp[i]); closure->run_envp[i] = strdup(envp[i]);
if (closure->run_envp[i] == NULL) if (closure->run_envp[i] == NULL)
goto oom; goto oom;
@@ -562,7 +564,7 @@ intercept_check_policy_req(PolicyCheckRequest *req,
size_t n; size_t n;
debug_decl(intercept_check_policy_req, SUDO_DEBUG_EXEC); debug_decl(intercept_check_policy_req, SUDO_DEBUG_EXEC);
if (req->command == NULL) { if (req->command == NULL || req->n_argv > INT_MAX || req->n_envp > INT_MAX) {
closure->errstr = N_("invalid PolicyCheckRequest"); closure->errstr = N_("invalid PolicyCheckRequest");
goto done; goto done;
} }
@@ -595,8 +597,8 @@ intercept_check_policy_req(PolicyCheckRequest *req,
} }
argv[n] = NULL; argv[n] = NULL;
ret = intercept_check_policy(req->command, req->n_argv, argv, req->n_envp, ret = intercept_check_policy(req->command, (int)req->n_argv, argv,
req->envp, req->cwd, &oldcwd, closure); (int)req->n_envp, req->envp, req->cwd, &oldcwd, closure);
done: done:
if (oldcwd != -1) { if (oldcwd != -1) {
@@ -635,7 +637,7 @@ intercept_verify_token(int fd, struct intercept_closure *closure)
if (nread + closure->off == sizeof(closure->token)) if (nread + closure->off == sizeof(closure->token))
break; break;
/* partial read, update offset and try again */ /* partial read, update offset and try again */
closure->off += nread; closure->off += (uint32_t)nread;
errno = EAGAIN; errno = EAGAIN;
debug_return_int(-1); debug_return_int(-1);
} }
@@ -734,7 +736,7 @@ intercept_read(int fd, struct intercept_closure *closure)
sudo_warn("recv"); sudo_warn("recv");
goto done; goto done;
default: default:
closure->off += nread; closure->off += (uint32_t)nread;
break; break;
} }
sudo_debug_printf(SUDO_DEBUG_INFO, "%s: received %zd bytes from client", sudo_debug_printf(SUDO_DEBUG_INFO, "%s: received %zd bytes from client",
@@ -820,7 +822,7 @@ fmt_intercept_response(InterceptResponse *resp,
bool ret = false; bool ret = false;
debug_decl(fmt_intercept_response, SUDO_DEBUG_EXEC); debug_decl(fmt_intercept_response, SUDO_DEBUG_EXEC);
closure->len = intercept_response__get_packed_size(resp); closure->len = (uint32_t)intercept_response__get_packed_size(resp);
if (closure->len > MESSAGE_SIZE_MAX) { if (closure->len > MESSAGE_SIZE_MAX) {
sudo_warnx(U_("server message too large: %zu"), (size_t)closure->len); sudo_warnx(U_("server message too large: %zu"), (size_t)closure->len);
goto done; goto done;
@@ -968,7 +970,7 @@ intercept_write(int fd, struct intercept_closure *closure)
sudo_warn("send"); sudo_warn("send");
goto done; goto done;
} }
closure->off += nwritten; closure->off += (uint32_t)nwritten;
if (closure->off != closure->len) { if (closure->off != closure->len) {
/* Partial write. */ /* Partial write. */

View File

@@ -145,7 +145,7 @@ send_status(int fd, struct command_status *cstat)
} }
cstat->type = CMD_INVALID; /* prevent re-sending */ cstat->type = CMD_INVALID; /* prevent re-sending */
} }
debug_return_int(n); debug_return_ssize_t(n);
} }
/* /*

View File

@@ -64,8 +64,8 @@ handle_sigwinch(struct exec_closure *ec, int fd)
log_winchange(ec, wsize.ws_row, wsize.ws_col); log_winchange(ec, wsize.ws_row, wsize.ws_col);
/* Update rows/cols. */ /* Update rows/cols. */
ec->rows = wsize.ws_row; ec->rows = (short)wsize.ws_row;
ec->cols = wsize.ws_col; ec->cols = (short)wsize.ws_col;
} }
} }
} }
@@ -218,8 +218,8 @@ fill_exec_closure(struct exec_closure *ec, struct command_status *cstat,
ec->ppgrp = getpgrp(); ec->ppgrp = getpgrp();
ec->cstat = cstat; ec->cstat = cstat;
ec->details = details; ec->details = details;
ec->rows = user_details->ts_rows; ec->rows = (short)user_details->ts_rows;
ec->cols = user_details->ts_cols; ec->cols = (short)user_details->ts_cols;
/* Setup event base and events. */ /* Setup event base and events. */
ec->evbase = evbase; ec->evbase = evbase;
@@ -373,11 +373,11 @@ read_callback(int fd, int what, void *v)
default: default:
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"read %zd bytes from fd %d", n, fd); "read %zd bytes from fd %d", n, fd);
if (!iob->action(iob->buf + iob->len, n, iob)) { if (!iob->action(iob->buf + iob->len, (unsigned int)n, iob)) {
terminate_command(iob->ec->cmnd_pid, false); terminate_command(iob->ec->cmnd_pid, false);
iob->ec->cmnd_pid = -1; iob->ec->cmnd_pid = -1;
} }
iob->len += n; iob->len += (unsigned int)n;
/* Disable reader if buffer is full. */ /* Disable reader if buffer is full. */
if (iob->len == sizeof(iob->buf)) if (iob->len == sizeof(iob->buf))
sudo_ev_del(evbase, iob->revent); sudo_ev_del(evbase, iob->revent);
@@ -410,7 +410,7 @@ write_callback(int fd, int what, void *v)
case EBADF: case EBADF:
/* other end of pipe closed */ /* other end of pipe closed */
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"unable to write %d bytes to fd %d", "unable to write %u bytes to fd %d",
iob->len - iob->off, fd); iob->len - iob->off, fd);
/* Close reader if there is one. */ /* Close reader if there is one. */
if (iob->revent != NULL) { if (iob->revent != NULL) {
@@ -436,7 +436,7 @@ write_callback(int fd, int what, void *v)
} else { } else {
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"wrote %zd bytes to fd %d", n, fd); "wrote %zd bytes to fd %d", n, fd);
iob->off += n; iob->off += (unsigned int)n;
/* Disable writer and reset the buffer if fully consumed. */ /* Disable writer and reset the buffer if fully consumed. */
if (iob->off == iob->len) { if (iob->off == iob->len) {
iob->off = iob->len = 0; iob->off = iob->len = 0;

View File

@@ -77,7 +77,8 @@ fmtstr(sudo_alloc_fn_t alloc_fn, sudo_free_fn_t free_fn, const char *ofmt, ...)
continue; continue;
case 'd': { case 'd': {
char numbuf[(((sizeof(int) * 8) + 2) / 3) + 2]; char numbuf[(((sizeof(int) * 8) + 2) / 3) + 2];
len = snprintf(numbuf, sizeof(numbuf), "%d", va_arg(ap, int)); len = (size_t)snprintf(numbuf, sizeof(numbuf), "%d",
va_arg(ap, int));
if (len >= sizeof(numbuf)) { if (len >= sizeof(numbuf)) {
goto oflow; goto oflow;
} }
@@ -117,7 +118,7 @@ fmtstr(sudo_alloc_fn_t alloc_fn, sudo_free_fn_t free_fn, const char *ofmt, ...)
if (size < 2) { if (size < 2) {
goto oflow; goto oflow;
} }
*cur++ = va_arg(ap, int); *cur++ = (char )va_arg(ap, int);
size--; size--;
fmt += 2; fmt += 2;
continue; continue;
@@ -132,7 +133,7 @@ fmtstr(sudo_alloc_fn_t alloc_fn, sudo_free_fn_t free_fn, const char *ofmt, ...)
fmt += 2; fmt += 2;
continue; continue;
case 'd': case 'd':
len = snprintf(cur, size, "%d", va_arg(ap, int)); len = (size_t)snprintf(cur, size, "%d", va_arg(ap, int));
if (len >= size) { if (len >= size) {
goto oflow; goto oflow;
} }
@@ -267,7 +268,7 @@ sudo_preload_dso_alloc(char *const envp[], const char *dso_file,
if (intercept_ptr != NULL) if (intercept_ptr != NULL)
continue; continue;
fd = sudo_strtonum(cp, 0, INT_MAX, &errstr); fd = (int)sudo_strtonum(cp, 0, INT_MAX, &errstr);
if (fd == intercept_fd && errstr == NULL) if (fd == intercept_fd && errstr == NULL)
fd_present = true; fd_present = true;

View File

@@ -351,7 +351,7 @@ ptrace_setregs(int pid, struct sudo_ptrace_regs *regs)
* Read the string at addr and store in buf using process_vm_readv(2). * Read the string at addr and store in buf using process_vm_readv(2).
* Returns the number of bytes stored, including the NUL. * Returns the number of bytes stored, including the NUL.
*/ */
static size_t static ssize_t
ptrace_readv_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize) ptrace_readv_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize)
{ {
const char *cp, *buf0 = buf; const char *cp, *buf0 = buf;
@@ -395,11 +395,11 @@ ptrace_readv_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize)
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
default: default:
/* Check for NUL terminator in page. */ /* Check for NUL terminator in page. */
cp = memchr(buf, '\0', nread); cp = memchr(buf, '\0', (size_t)nread);
if (cp != NULL) if (cp != NULL)
debug_return_size_t((cp - buf0) + 1); /* includes NUL */ debug_return_ssize_t((cp - buf0) + 1); /* includes NUL */
buf += nread; buf += nread;
bufsize -= nread; bufsize -= (size_t)nread;
addr += sizeof(unsigned long); addr += sizeof(unsigned long);
break; break;
} }
@@ -412,7 +412,7 @@ ptrace_readv_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize)
* Read the string at addr and store in buf using ptrace(2). * Read the string at addr and store in buf using ptrace(2).
* Returns the number of bytes stored, including the NUL. * Returns the number of bytes stored, including the NUL.
*/ */
static size_t static ssize_t
ptrace_read_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize) ptrace_read_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize)
{ {
const char *cp, *buf0 = buf; const char *cp, *buf0 = buf;
@@ -421,9 +421,9 @@ ptrace_read_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize)
debug_decl(ptrace_read_string, SUDO_DEBUG_EXEC); debug_decl(ptrace_read_string, SUDO_DEBUG_EXEC);
#ifdef HAVE_PROCESS_VM_READV #ifdef HAVE_PROCESS_VM_READV
i = ptrace_readv_string(pid, addr, buf, bufsize); ssize_t nread = ptrace_readv_string(pid, addr, buf, bufsize);
if (i != (size_t)-1 || errno != ENOSYS) if (nread != -1 || errno != ENOSYS)
debug_return_size_t(i); debug_return_ssize_t(nread);
#endif /* HAVE_PROCESS_VM_READV */ #endif /* HAVE_PROCESS_VM_READV */
/* /*
@@ -450,7 +450,7 @@ ptrace_read_string(pid_t pid, unsigned long addr, char *buf, size_t bufsize)
} }
*buf = cp[i]; *buf = cp[i];
if (*buf++ == '\0') if (*buf++ == '\0')
debug_return_size_t(buf - buf0); debug_return_ssize_t(buf - buf0);
bufsize--; bufsize--;
} }
addr += sizeof(unsigned long); addr += sizeof(unsigned long);
@@ -493,7 +493,7 @@ growbuf(char **bufp, size_t *bufsizep, char **curp, size_t *remp)
* However, NULL is still stored as NULL. * However, NULL is still stored as NULL.
* Returns (size_t)-1 on failure. * Returns (size_t)-1 on failure.
*/ */
static size_t static ssize_t
strtab_to_vec(char *strtab, size_t strtab_len, int *countp, char ***vecp, strtab_to_vec(char *strtab, size_t strtab_len, int *countp, char ***vecp,
char **bufp, size_t *bufsizep, size_t remainder) char **bufp, size_t *bufsizep, size_t remainder)
{ {
@@ -509,7 +509,7 @@ strtab_to_vec(char *strtab, size_t strtab_len, int *countp, char ***vecp,
strend = strtab + strtab_len; strend = strtab + strtab_len;
} }
vec = (char **)LONGALIGN(strend); vec = (char **)LONGALIGN(strend);
remainder -= (char *)vec - strend; remainder -= (size_t)((char *)vec - strend);
/* Fill in vector with the strings we read. */ /* Fill in vector with the strings we read. */
for (vp = vec; strtab < strend; ) { for (vp = vec; strtab < strend; ) {
@@ -523,7 +523,7 @@ strtab_to_vec(char *strtab, size_t strtab_len, int *countp, char ***vecp,
/* Store offset into buf (not a pointer) in case of realloc(). */ /* Store offset into buf (not a pointer) in case of realloc(). */
*vp++ = (char *)(strtab - *bufp); *vp++ = (char *)(strtab - *bufp);
remainder -= sizeof(char *); remainder -= sizeof(char *);
strtab = memchr(strtab, '\0', strend - strtab); strtab = memchr(strtab, '\0', (size_t)(strend - strtab));
if (strtab == NULL) if (strtab == NULL)
break; break;
strtab++; strtab++;
@@ -534,7 +534,7 @@ strtab_to_vec(char *strtab, size_t strtab_len, int *countp, char ***vecp,
*countp = count; *countp = count;
*vecp = (char **)((char *)vec - *bufp); *vecp = (char **)((char *)vec - *bufp);
debug_return_size_t((char *)vp - strend); debug_return_ssize_t((char *)vp - strend);
} }
/* /*
@@ -546,17 +546,17 @@ strtab_to_vec(char *strtab, size_t strtab_len, int *countp, char ***vecp,
* offsets into pointers based on the buffer before using. * offsets into pointers based on the buffer before using.
* Returns the number of bytes in buf consumed (including NULs). * Returns the number of bytes in buf consumed (including NULs).
*/ */
static size_t static ssize_t
ptrace_read_vec(pid_t pid, struct sudo_ptrace_regs *regs, unsigned long addr, ptrace_read_vec(pid_t pid, struct sudo_ptrace_regs *regs, unsigned long addr,
int *countp, char ***vecp, char **bufp, size_t *bufsizep, size_t off) int *countp, char ***vecp, char **bufp, size_t *bufsizep, size_t off)
{ {
# ifdef SECCOMP_AUDIT_ARCH_COMPAT # ifdef SECCOMP_AUDIT_ARCH_COMPAT
unsigned long next_word = -1; unsigned long next_word = (unsigned long)-1;
# endif # endif
size_t remainder = *bufsizep - off; size_t strtab_len, remainder = *bufsizep - off;
char *strtab = *bufp + off; char *strtab = *bufp + off;
unsigned long word; unsigned long word;
size_t len, strtab_len; ssize_t len;
debug_decl(ptrace_read_vec, SUDO_DEBUG_EXEC); debug_decl(ptrace_read_vec, SUDO_DEBUG_EXEC);
/* Treat a NULL vector as empty, thanks Linux. */ /* Treat a NULL vector as empty, thanks Linux. */
@@ -571,7 +571,7 @@ ptrace_read_vec(pid_t pid, struct sudo_ptrace_regs *regs, unsigned long addr,
*vecp = (char **)((char *)vp - *bufp); *vecp = (char **)((char *)vp - *bufp);
*countp = 0; *countp = 0;
*vp++ = NULL; *vp++ = NULL;
debug_return_size_t((char *)vp - strtab); debug_return_ssize_t((char *)vp - strtab);
} }
/* Fill in string table. */ /* Fill in string table. */
@@ -608,7 +608,7 @@ ptrace_read_vec(pid_t pid, struct sudo_ptrace_regs *regs, unsigned long addr,
default: default:
for (;;) { for (;;) {
len = ptrace_read_string(pid, word, strtab, remainder); len = ptrace_read_string(pid, word, strtab, remainder);
if (len != (size_t)-1) if (len != -1)
break; break;
if (errno != ENOSPC) if (errno != ENOSPC)
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
@@ -616,21 +616,21 @@ ptrace_read_vec(pid_t pid, struct sudo_ptrace_regs *regs, unsigned long addr,
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
} }
strtab += len; strtab += len;
remainder -= len; remainder -= (size_t)len;
addr += regs->wordsize; addr += regs->wordsize;
continue; continue;
} }
} while (word != 0); } while (word != 0);
/* Store strings in a vector after the string table. */ /* Store strings in a vector after the string table. */
strtab_len = strtab - (*bufp + off); strtab_len = (size_t)(strtab - (*bufp + off));
strtab = *bufp + off; strtab = *bufp + off;
len = strtab_to_vec(strtab, strtab_len, countp, vecp, bufp, bufsizep, len = strtab_to_vec(strtab, strtab_len, countp, vecp, bufp, bufsizep,
remainder); remainder);
if (len == (size_t)-1) if (len == -1)
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
debug_return_size_t(strtab_len + len); debug_return_ssize_t((ssize_t)strtab_len + len);
} }
#ifdef HAVE_PROCESS_VM_READV #ifdef HAVE_PROCESS_VM_READV
@@ -639,7 +639,7 @@ ptrace_read_vec(pid_t pid, struct sudo_ptrace_regs *regs, unsigned long addr,
* process_vm_writev(2). * process_vm_writev(2).
* Returns the number of bytes written, including trailing NUL. * Returns the number of bytes written, including trailing NUL.
*/ */
static size_t static ssize_t
ptrace_writev_string(pid_t pid, unsigned long addr, const char *str0) ptrace_writev_string(pid_t pid, unsigned long addr, const char *str0)
{ {
const char *str = str0; const char *str = str0;
@@ -678,10 +678,10 @@ ptrace_writev_string(pid_t pid, unsigned long addr, const char *str0)
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
default: default:
str += nwritten; str += nwritten;
len -= nwritten; len -= (size_t)nwritten;
addr += nwritten; addr += (size_t)nwritten;
if (len == 0) if (len == 0)
debug_return_size_t(str - str0); /* includes NUL */ debug_return_ssize_t(str - str0); /* includes NUL */
break; break;
} }
} }
@@ -693,7 +693,7 @@ ptrace_writev_string(pid_t pid, unsigned long addr, const char *str0)
* Write the NUL-terminated string str to addr in the tracee using ptrace(2). * Write the NUL-terminated string str to addr in the tracee using ptrace(2).
* Returns the number of bytes written, including trailing NUL. * Returns the number of bytes written, including trailing NUL.
*/ */
static size_t static ssize_t
ptrace_write_string(pid_t pid, unsigned long addr, const char *str) ptrace_write_string(pid_t pid, unsigned long addr, const char *str)
{ {
const char *str0 = str; const char *str0 = str;
@@ -705,9 +705,9 @@ ptrace_write_string(pid_t pid, unsigned long addr, const char *str)
debug_decl(ptrace_write_string, SUDO_DEBUG_EXEC); debug_decl(ptrace_write_string, SUDO_DEBUG_EXEC);
#ifdef HAVE_PROCESS_VM_READV #ifdef HAVE_PROCESS_VM_READV
i = ptrace_writev_string(pid, addr, str); ssize_t nwritten = ptrace_writev_string(pid, addr, str);
if (i != (size_t)-1 || errno != ENOSYS) if (nwritten != -1 || errno != ENOSYS)
debug_return_size_t(i); debug_return_ssize_t(nwritten);
#endif /* HAVE_PROCESS_VM_READV */ #endif /* HAVE_PROCESS_VM_READV */
/* /*
@@ -731,7 +731,7 @@ ptrace_write_string(pid_t pid, unsigned long addr, const char *str)
} }
if ((u.word & 0xff) == 0) { if ((u.word & 0xff) == 0) {
/* If the last byte we wrote is a NUL we are done. */ /* If the last byte we wrote is a NUL we are done. */
debug_return_size_t(str - str0 + 1); debug_return_ssize_t(str - str0 + 1);
} }
addr += sizeof(unsigned long); addr += sizeof(unsigned long);
} }
@@ -744,7 +744,7 @@ ptrace_write_string(pid_t pid, unsigned long addr, const char *str)
* Returns the number of bytes used in strtab (including NULs). * Returns the number of bytes used in strtab (including NULs).
* process_vm_writev() version. * process_vm_writev() version.
*/ */
static size_t static ssize_t
ptrace_writev_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec, ptrace_writev_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
unsigned long addr, unsigned long strtab) unsigned long addr, unsigned long strtab)
{ {
@@ -817,7 +817,7 @@ ptrace_writev_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
goto done; goto done;
/* Copy the strings to the (remote) string table. */ /* Copy the strings to the (remote) string table. */
expected = strtab - strtab0; expected = (ssize_t)(strtab - strtab0);
for (;;) { for (;;) {
nwritten = process_vm_writev(pid, local + off, len - off, nwritten = process_vm_writev(pid, local + off, len - off,
remote + off, len - off, 0); remote + off, len - off, 0);
@@ -844,7 +844,7 @@ ptrace_writev_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
/* Adjust offset for partial write (doesn't cross iov boundary). */ /* Adjust offset for partial write (doesn't cross iov boundary). */
while (off < len) { while (off < len) {
nwritten -= local[off].iov_len; nwritten -= (ssize_t)local[off].iov_len;
off++; off++;
if (nwritten <= 0) if (nwritten <= 0)
break; break;
@@ -863,7 +863,7 @@ done:
free(remote); free(remote);
free(addrbuf); free(addrbuf);
if (total_written == expected) if (total_written == expected)
debug_return_size_t(total_written); debug_return_ssize_t(total_written);
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
} }
#endif /* HAVE_PROCESS_VM_READV */ #endif /* HAVE_PROCESS_VM_READV */
@@ -873,18 +873,18 @@ done:
* sufficient space. Strings are written to strtab. * sufficient space. Strings are written to strtab.
* Returns the number of bytes used in strtab (including NULs). * Returns the number of bytes used in strtab (including NULs).
*/ */
static size_t static ssize_t
ptrace_write_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec, ptrace_write_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
unsigned long addr, unsigned long strtab) unsigned long addr, unsigned long strtab)
{ {
const unsigned long strtab0 = strtab; const unsigned long strtab0 = strtab;
size_t i, len; size_t i;
debug_decl(ptrace_write_vec, SUDO_DEBUG_EXEC); debug_decl(ptrace_write_vec, SUDO_DEBUG_EXEC);
#ifdef HAVE_PROCESS_VM_READV #ifdef HAVE_PROCESS_VM_READV
i = ptrace_writev_vec(pid, regs, vec, addr, strtab); ssize_t nwritten = ptrace_writev_vec(pid, regs, vec, addr, strtab);
if (i != (size_t)-1 || errno != ENOSYS) if (nwritten != -1 || errno != ENOSYS)
debug_return_size_t(i); debug_return_ssize_t(nwritten);
#endif /* HAVE_PROCESS_VM_READV */ #endif /* HAVE_PROCESS_VM_READV */
/* Copy string vector into tracee one word at a time. */ /* Copy string vector into tracee one word at a time. */
@@ -892,10 +892,10 @@ ptrace_write_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
unsigned long word = strtab; unsigned long word = strtab;
/* First write the actual string to tracee's string table. */ /* First write the actual string to tracee's string table. */
len = ptrace_write_string(pid, strtab, vec[i]); nwritten = ptrace_write_string(pid, strtab, vec[i]);
if (len == (size_t)-1) if (nwritten == -1)
debug_return_int(-1); debug_return_ssize_t(-1);
strtab += len; strtab += (size_t)nwritten;
# ifdef SECCOMP_AUDIT_ARCH_COMPAT # ifdef SECCOMP_AUDIT_ARCH_COMPAT
if (regs->compat) { if (regs->compat) {
@@ -922,7 +922,7 @@ ptrace_write_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
if (ptrace(PTRACE_POKEDATA, pid, addr, word) == -1) { if (ptrace(PTRACE_POKEDATA, pid, addr, word) == -1) {
sudo_warn("%s: ptrace(PTRACE_POKEDATA, %d, 0x%lx, 0x%lx)", sudo_warn("%s: ptrace(PTRACE_POKEDATA, %d, 0x%lx, 0x%lx)",
__func__, (int)pid, addr, word); __func__, (int)pid, addr, word);
debug_return_int(-1); debug_return_ssize_t(-1);
} }
addr += sizeof(unsigned long); addr += sizeof(unsigned long);
} }
@@ -932,11 +932,11 @@ ptrace_write_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
if (ptrace(PTRACE_POKEDATA, pid, addr, NULL) == -1) { if (ptrace(PTRACE_POKEDATA, pid, addr, NULL) == -1) {
sudo_warn("%s: ptrace(PTRACE_POKEDATA, %d, 0x%lx, NULL)", sudo_warn("%s: ptrace(PTRACE_POKEDATA, %d, 0x%lx, NULL)",
__func__, (int)pid, addr); __func__, (int)pid, addr);
debug_return_int(-1); debug_return_ssize_t(-1);
} }
} }
debug_return_size_t(strtab - strtab0); debug_return_ssize_t((ssize_t)(strtab - strtab0));
} }
/* /*
@@ -947,14 +947,14 @@ ptrace_write_vec(pid_t pid, struct sudo_ptrace_regs *regs, char **vec,
static bool static bool
proc_read_link(pid_t pid, const char *name, char *buf, size_t bufsize) proc_read_link(pid_t pid, const char *name, char *buf, size_t bufsize)
{ {
size_t len; ssize_t len;
char path[PATH_MAX]; char path[PATH_MAX];
debug_decl(proc_read_link, SUDO_DEBUG_EXEC); debug_decl(proc_read_link, SUDO_DEBUG_EXEC);
len = snprintf(path, sizeof(path), "/proc/%d/%s", (int)pid, name); len = snprintf(path, sizeof(path), "/proc/%d/%s", (int)pid, name);
if (len < sizeof(path)) { if (len > 0 && len < ssizeof(path)) {
len = readlink(path, buf, bufsize - 1); len = readlink(path, buf, bufsize - 1);
if (len != (size_t)-1) { if (len != -1) {
/* readlink(2) does not add the NUL for us. */ /* readlink(2) does not add the NUL for us. */
buf[len] = '\0'; buf[len] = '\0';
debug_return_bool(true); debug_return_bool(true);
@@ -973,8 +973,9 @@ get_execve_info(pid_t pid, struct sudo_ptrace_regs *regs, char **pathname_out,
{ {
char *argbuf, **argv, **envp, *pathname = NULL; char *argbuf, **argv, **envp, *pathname = NULL;
unsigned long argv_addr, envp_addr, path_addr; unsigned long argv_addr, envp_addr, path_addr;
size_t bufsize, len, off = 0; size_t bufsize, off = 0;
int i, argc, envc = 0; int i, argc, envc = 0;
ssize_t nread;
debug_decl(get_execve_info, SUDO_DEBUG_EXEC); debug_decl(get_execve_info, SUDO_DEBUG_EXEC);
bufsize = PATH_MAX + arg_max; bufsize = PATH_MAX + arg_max;
@@ -994,27 +995,27 @@ get_execve_info(pid_t pid, struct sudo_ptrace_regs *regs, char **pathname_out,
/* Read the pathname, if not NULL. */ /* Read the pathname, if not NULL. */
if (path_addr != 0) { if (path_addr != 0) {
len = ptrace_read_string(pid, path_addr, argbuf, bufsize); nread = ptrace_read_string(pid, path_addr, argbuf, bufsize);
if (len == (size_t)-1) { if (nread == -1) {
sudo_debug_printf( sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"unable to read execve pathname for process %d", (int)pid); "unable to read execve pathname for process %d", (int)pid);
goto bad; goto bad;
} }
/* Defer setting pathname until after all reallocations are done. */ /* Defer setting pathname until after all reallocations are done. */
off = len; off = (size_t)nread;
} }
/* Read argv */ /* Read argv */
len = ptrace_read_vec(pid, regs, argv_addr, &argc, &argv, &argbuf, nread = ptrace_read_vec(pid, regs, argv_addr, &argc, &argv, &argbuf,
&bufsize, off); &bufsize, off);
if (len == (size_t)-1) { if (nread == -1) {
sudo_debug_printf( sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"unable to read execve argv for process %d", (int)pid); "unable to read execve argv for process %d", (int)pid);
goto bad; goto bad;
} }
off += len; off += (size_t)nread;
if (argc == 0) { if (argc == 0) {
/* Reserve an extra slot so we can store argv[0]. */ /* Reserve an extra slot so we can store argv[0]. */
@@ -1026,9 +1027,9 @@ get_execve_info(pid_t pid, struct sudo_ptrace_regs *regs, char **pathname_out,
} }
/* Read envp */ /* Read envp */
len = ptrace_read_vec(pid, regs, envp_addr, &envc, &envp, &argbuf, nread = ptrace_read_vec(pid, regs, envp_addr, &envc, &envp, &argbuf,
&bufsize, off); &bufsize, off);
if (len == (size_t)-1) { if (nread == -1) {
sudo_debug_printf( sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"unable to read execve envp for process %d", (int)pid); "unable to read execve envp for process %d", (int)pid);
@@ -1228,11 +1229,11 @@ exec_ptrace_seize(pid_t child)
debug_decl(exec_ptrace_seize, SUDO_DEBUG_EXEC); debug_decl(exec_ptrace_seize, SUDO_DEBUG_EXEC);
#ifdef HAVE_PROCESS_VM_READV #ifdef HAVE_PROCESS_VM_READV
page_size = sysconf(_SC_PAGESIZE); page_size = (size_t)sysconf(_SC_PAGESIZE);
if (page_size == (size_t)-1) if (page_size == (size_t)-1)
page_size = 4096; page_size = 4096;
#endif #endif
arg_max = sysconf(_SC_ARG_MAX); arg_max = (size_t)sysconf(_SC_ARG_MAX);
if (arg_max == (size_t)-1) if (arg_max == (size_t)-1)
arg_max = 128 * 1024; arg_max = 128 * 1024;
@@ -1420,19 +1421,18 @@ done:
debug_return_int((int)(argv - orig_argv)); debug_return_int((int)(argv - orig_argv));
} }
static size_t static ssize_t
proc_read_vec(pid_t pid, const char *name, int *countp, char ***vecp, proc_read_vec(pid_t pid, const char *name, int *countp, char ***vecp,
char **bufp, size_t *bufsizep, size_t off) char **bufp, size_t *bufsizep, size_t off)
{ {
size_t remainder = *bufsizep - off; size_t strtab_len, remainder = *bufsizep - off;
size_t len, strtab_len;
char path[PATH_MAX], *strtab = *bufp + off; char path[PATH_MAX], *strtab = *bufp + off;
ssize_t len, nread;
int fd; int fd;
ssize_t nread;
debug_decl(proc_read_vec, SUDO_DEBUG_EXEC); debug_decl(proc_read_vec, SUDO_DEBUG_EXEC);
len = snprintf(path, sizeof(path), "/proc/%d/%s", (int)pid, name); len = snprintf(path, sizeof(path), "/proc/%d/%s", (int)pid, name);
if (len >= sizeof(path)) if (len >= ssizeof(path))
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
@@ -1449,7 +1449,7 @@ proc_read_vec(pid_t pid, const char *name, int *countp, char ***vecp,
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
} }
strtab += nread; strtab += nread;
remainder -= nread; remainder -= (size_t)nread;
if (remainder < sizeof(char *)) { if (remainder < sizeof(char *)) {
while (!growbuf(bufp, bufsizep, &strtab, &remainder)) { while (!growbuf(bufp, bufsizep, &strtab, &remainder)) {
close(fd); close(fd);
@@ -1466,14 +1466,14 @@ proc_read_vec(pid_t pid, const char *name, int *countp, char ***vecp,
} }
/* Store strings in a vector after the string table. */ /* Store strings in a vector after the string table. */
strtab_len = strtab - (*bufp + off); strtab_len = (size_t)(strtab - (*bufp + off));
strtab = *bufp + off; strtab = *bufp + off;
len = strtab_to_vec(strtab, strtab_len, countp, vecp, bufp, bufsizep, len = strtab_to_vec(strtab, strtab_len, countp, vecp, bufp, bufsizep,
remainder); remainder);
if (len == (size_t)-1) if (len == -1)
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
debug_return_size_t(strtab_len + len); debug_return_ssize_t((ssize_t)strtab_len + len);
} }
/* /*
@@ -1606,7 +1606,8 @@ ptrace_verify_post_exec(pid_t pid, struct sudo_ptrace_regs *regs,
sigset_t chldmask; sigset_t chldmask;
bool ret = false; bool ret = false;
int argc, envc, i, status; int argc, envc, i, status;
size_t bufsize, len; size_t bufsize;
ssize_t len;
debug_decl(ptrace_verify_post_exec, SUDO_DEBUG_EXEC); debug_decl(ptrace_verify_post_exec, SUDO_DEBUG_EXEC);
/* Block SIGCHLD for the critical section (waitpid). */ /* Block SIGCHLD for the critical section (waitpid). */
@@ -1653,15 +1654,16 @@ ptrace_verify_post_exec(pid_t pid, struct sudo_ptrace_regs *regs,
} }
len = proc_read_vec(pid, "cmdline", &argc, &argv, &argbuf, &bufsize, 0); len = proc_read_vec(pid, "cmdline", &argc, &argv, &argbuf, &bufsize, 0);
if (len == (size_t)-1) { if (len == -1) {
sudo_debug_printf( sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"unable to read execve argv for process %d", (int)pid); "unable to read execve argv for process %d", (int)pid);
goto done; goto done;
} }
len = proc_read_vec(pid, "environ", &envc, &envp, &argbuf, &bufsize, len); len = proc_read_vec(pid, "environ", &envc, &envp, &argbuf, &bufsize,
if (len == (size_t)-1) { (size_t)len);
if (len == -1) {
sudo_debug_printf( sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"unable to read execve envp for process %d", (int)pid); "unable to read execve envp for process %d", (int)pid);
@@ -1861,7 +1863,8 @@ ptrace_intercept_execve(pid_t pid, struct intercept_closure *closure)
*/ */
unsigned long sp = get_stack_pointer(&regs) - 128; unsigned long sp = get_stack_pointer(&regs) - 128;
unsigned long strtab; unsigned long strtab;
size_t len, space = 0; size_t space = 0;
ssize_t nwritten;
sudo_debug_execve(SUDO_DEBUG_DIAG, closure->command, sudo_debug_execve(SUDO_DEBUG_DIAG, closure->command,
closure->run_argv, envp); closure->run_argv, envp);
@@ -1881,7 +1884,7 @@ ptrace_intercept_execve(pid_t pid, struct intercept_closure *closure)
*/ */
if (argv_mismatch) { if (argv_mismatch) {
/* argv pointers */ /* argv pointers */
space += (argc + 1 + regs.compat) * regs.wordsize; space += (size_t)(argc + 1 + regs.compat) * regs.wordsize;
/* argv strings */ /* argv strings */
for (argc = 0; closure->run_argv[argc] != NULL; argc++) { for (argc = 0; closure->run_argv[argc] != NULL; argc++) {
@@ -1902,21 +1905,21 @@ ptrace_intercept_execve(pid_t pid, struct intercept_closure *closure)
set_sc_arg2(&regs, sp); set_sc_arg2(&regs, sp);
/* Skip over argv pointers (plus NULL) for string table. */ /* Skip over argv pointers (plus NULL) for string table. */
strtab += (argc + 1 + regs.compat) * regs.wordsize; strtab += (size_t)(argc + 1 + regs.compat) * regs.wordsize;
len = ptrace_write_vec(pid, &regs, closure->run_argv, nwritten = ptrace_write_vec(pid, &regs, closure->run_argv,
sp, strtab); sp, strtab);
if (len == (size_t)-1) if (nwritten == -1)
goto done; goto done;
strtab += len; strtab += (unsigned long)nwritten;
} }
if (path_mismatch) { if (path_mismatch) {
/* Update pathname address in the tracee to our new value. */ /* Update pathname address in the tracee to our new value. */
set_sc_arg1(&regs, strtab); set_sc_arg1(&regs, strtab);
/* Write pathname to the string table. */ /* Write pathname to the string table. */
len = ptrace_write_string(pid, strtab, closure->command); nwritten = ptrace_write_string(pid, strtab, closure->command);
if (len == (size_t)-1) if (nwritten == -1)
goto done; goto done;
} }

View File

@@ -418,11 +418,11 @@ read_callback(int fd, int what, void *v)
default: default:
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"read %zd bytes from fd %d", n, fd); "read %zd bytes from fd %d", n, fd);
if (!iob->action(iob->buf + iob->len, n, iob)) { if (!iob->action(iob->buf + iob->len, (unsigned int)n, iob)) {
terminate_command(iob->ec->cmnd_pid, true); terminate_command(iob->ec->cmnd_pid, true);
iob->ec->cmnd_pid = -1; iob->ec->cmnd_pid = -1;
} }
iob->len += n; iob->len += (unsigned int)n;
/* Disable reader if buffer is full. */ /* Disable reader if buffer is full. */
if (iob->len == sizeof(iob->buf)) if (iob->len == sizeof(iob->buf))
sudo_ev_del(evbase, iob->revent); sudo_ev_del(evbase, iob->revent);
@@ -484,7 +484,7 @@ write_callback(int fd, int what, void *v)
case EBADF: case EBADF:
/* other end of pipe closed or pty revoked */ /* other end of pipe closed or pty revoked */
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"unable to write %d bytes to fd %d", "unable to write %u bytes to fd %d",
iob->len - iob->off, fd); iob->len - iob->off, fd);
/* Close reader if there is one. */ /* Close reader if there is one. */
if (iob->revent != NULL) { if (iob->revent != NULL) {
@@ -515,7 +515,7 @@ write_callback(int fd, int what, void *v)
} else { } else {
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"wrote %zd bytes to fd %d", n, fd); "wrote %zd bytes to fd %d", n, fd);
iob->off += n; iob->off += (unsigned int)n;
/* Disable writer and reset the buffer if fully consumed. */ /* Disable writer and reset the buffer if fully consumed. */
if (iob->off == iob->len) { if (iob->off == iob->len) {
iob->off = iob->len = 0; iob->off = iob->len = 0;
@@ -946,8 +946,8 @@ fill_exec_closure(struct exec_closure *ec, struct command_status *cstat,
ec->cmnd_pid = -1; ec->cmnd_pid = -1;
ec->cstat = cstat; ec->cstat = cstat;
ec->details = details; ec->details = details;
ec->rows = user_details->ts_rows; ec->rows = (short)user_details->ts_rows;
ec->cols = user_details->ts_cols; ec->cols = (short)user_details->ts_cols;
/* Reset cstat for running the command. */ /* Reset cstat for running the command. */
cstat->type = CMD_INVALID; cstat->type = CMD_INVALID;
@@ -1464,8 +1464,8 @@ sync_ttysize(struct exec_closure *ec)
killpg(ec->cmnd_pid, SIGWINCH); killpg(ec->cmnd_pid, SIGWINCH);
/* Update rows/cols. */ /* Update rows/cols. */
ec->rows = wsize.ws_row; ec->rows = (short)wsize.ws_row;
ec->cols = wsize.ws_col; ec->cols = (short)wsize.ws_col;
} }
} }

View File

@@ -140,7 +140,7 @@ get_net_ifs(char **addrinfo_out)
} }
if (num_interfaces == 0) if (num_interfaces == 0)
goto done; goto done;
ailen = num_interfaces * 2 * INET6_ADDRSTRLEN; ailen = (size_t)num_interfaces * 2 * INET6_ADDRSTRLEN;
if ((cp = malloc(ailen)) == NULL) { if ((cp = malloc(ailen)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory"); "unable to allocate memory");
@@ -207,7 +207,7 @@ get_net_ifs(char **addrinfo_out)
goto bad; goto bad;
} }
cp += len; cp += len;
ailen -= len; ailen -= (size_t)len;
} }
*addrinfo_out = addrinfo; *addrinfo_out = addrinfo;
goto done; goto done;

View File

@@ -642,7 +642,7 @@ parse_args(int argc, char **argv, const char *shell, int *old_optind,
ac += 2; /* -c cmnd */ ac += 2; /* -c cmnd */
} }
av = reallocarray(NULL, ac + 1, sizeof(char *)); av = reallocarray(NULL, (size_t)ac + 1, sizeof(char *));
if (av == NULL) if (av == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
if (!gc_add(GC_PTR, av)) if (!gc_add(GC_PTR, av))
@@ -667,7 +667,7 @@ parse_args(int argc, char **argv, const char *shell, int *old_optind,
char **av; char **av;
int ac; int ac;
av = reallocarray(NULL, argc + 2, sizeof(char *)); av = reallocarray(NULL, (size_t)argc + 2, sizeof(char *));
if (av == NULL) if (av == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
if (!gc_add(GC_PTR, av)) if (!gc_add(GC_PTR, av))
@@ -713,7 +713,7 @@ display_usage(FILE *fp)
if (strcmp(getprogname(), "sudoedit") == 0) if (strcmp(getprogname(), "sudoedit") == 0)
uvecs = sudoedit_usage; uvecs = sudoedit_usage;
indent = strlen(getprogname()) + 8; indent = (int)strlen(getprogname()) + 8;
while ((uvec = *uvecs) != NULL) { while ((uvec = *uvecs) != NULL) {
(void)fprintf(fp, "usage: %s %s\n", getprogname(), uvec[0]); (void)fprintf(fp, "usage: %s %s\n", getprogname(), uvec[0]);
for (i = 1; uvec[i] != NULL; i++) { for (i = 1; uvec[i] != NULL; i++) {

View File

@@ -126,7 +126,7 @@ closefrom_except(int startfd, struct preserved_fd_list *pfds)
} }
/* Create bitmap of preserved (relocated) fds. */ /* Create bitmap of preserved (relocated) fds. */
fdbits = calloc((lastfd + NBBY) / NBBY, 1); fdbits = calloc((size_t)(lastfd + NBBY) / NBBY, 1);
if (fdbits == NULL) if (fdbits == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
TAILQ_FOREACH(pfd, pfds, entries) { TAILQ_FOREACH(pfd, pfds, entries) {

View File

@@ -400,7 +400,8 @@ fill_group_list(const char *user, struct sudo_cred *cred)
*/ */
cred->ngroups = sudo_conf_max_groups(); cred->ngroups = sudo_conf_max_groups();
if (cred->ngroups > 0) { if (cred->ngroups > 0) {
cred->groups = reallocarray(NULL, cred->ngroups, sizeof(GETGROUPS_T)); cred->groups =
reallocarray(NULL, (size_t)cred->ngroups, sizeof(GETGROUPS_T));
if (cred->groups != NULL) { if (cred->groups != NULL) {
/* Clamp to max_groups if insufficient space for all groups. */ /* Clamp to max_groups if insufficient space for all groups. */
if (sudo_getgrouplist2(user, cred->gid, &cred->groups, if (sudo_getgrouplist2(user, cred->gid, &cred->groups,
@@ -446,7 +447,8 @@ get_user_groups(const char *user, struct sudo_cred *cred)
if (cred->ngroups > 0) { if (cred->ngroups > 0) {
/* Use groups from kernel if not at limit or source is static. */ /* Use groups from kernel if not at limit or source is static. */
if (cred->ngroups != maxgroups || group_source == GROUP_SOURCE_STATIC) { if (cred->ngroups != maxgroups || group_source == GROUP_SOURCE_STATIC) {
cred->groups = reallocarray(NULL, cred->ngroups, sizeof(GETGROUPS_T)); cred->groups = reallocarray(NULL, (size_t)cred->ngroups,
sizeof(GETGROUPS_T));
if (cred->groups == NULL) if (cred->groups == NULL)
goto done; goto done;
cred->ngroups = getgroups(cred->ngroups, cred->groups); cred->ngroups = getgroups(cred->ngroups, cred->groups);
@@ -476,17 +478,19 @@ get_user_groups(const char *user, struct sudo_cred *cred)
/* /*
* Format group list as a comma-separated string of gids. * Format group list as a comma-separated string of gids.
*/ */
glsize = sizeof("groups=") - 1 + (cred->ngroups * (MAX_UID_T_LEN + 1)); glsize = sizeof("groups=") - 1 + ((size_t)cred->ngroups * (MAX_UID_T_LEN + 1));
if ((gid_list = malloc(glsize)) == NULL) if ((gid_list = malloc(glsize)) == NULL)
goto done; goto done;
memcpy(gid_list, "groups=", sizeof("groups=") - 1); memcpy(gid_list, "groups=", sizeof("groups=") - 1);
cp = gid_list + sizeof("groups=") - 1; cp = gid_list + sizeof("groups=") - 1;
glsize -= (size_t)(cp - gid_list);
for (i = 0; i < cred->ngroups; i++) { for (i = 0; i < cred->ngroups; i++) {
len = snprintf(cp, glsize - (cp - gid_list), "%s%u", len = snprintf(cp, glsize, "%s%u", i ? "," : "",
i ? "," : "", (unsigned int)cred->groups[i]); (unsigned int)cred->groups[i]);
if (len < 0 || (size_t)len >= glsize - (cp - gid_list)) if (len < 0 || (size_t)len >= glsize)
sudo_fatalx(U_("internal error, %s overflow"), __func__); sudo_fatalx(U_("internal error, %s overflow"), __func__);
cp += len; cp += len;
glsize -= (size_t)len;
} }
done: done:
debug_return_str(gid_list); debug_return_str(gid_list);
@@ -704,7 +708,8 @@ command_info_to_details(char * const info[], struct command_details *details)
SET_FLAG("cwd_optional=", CD_CWD_OPTIONAL) SET_FLAG("cwd_optional=", CD_CWD_OPTIONAL)
if (strncmp("closefrom=", info[i], sizeof("closefrom=") - 1) == 0) { if (strncmp("closefrom=", info[i], sizeof("closefrom=") - 1) == 0) {
cp = info[i] + sizeof("closefrom=") - 1; cp = info[i] + sizeof("closefrom=") - 1;
details->closefrom = sudo_strtonum(cp, 0, INT_MAX, &errstr); details->closefrom =
(int)sudo_strtonum(cp, 0, INT_MAX, &errstr);
if (errstr != NULL) if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr)); sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
break; break;
@@ -714,7 +719,8 @@ command_info_to_details(char * const info[], struct command_details *details)
SET_FLAG("exec_background=", CD_EXEC_BG) SET_FLAG("exec_background=", CD_EXEC_BG)
if (strncmp("execfd=", info[i], sizeof("execfd=") - 1) == 0) { if (strncmp("execfd=", info[i], sizeof("execfd=") - 1) == 0) {
cp = info[i] + sizeof("execfd=") - 1; cp = info[i] + sizeof("execfd=") - 1;
details->execfd = sudo_strtonum(cp, 0, INT_MAX, &errstr); details->execfd =
(int)sudo_strtonum(cp, 0, INT_MAX, &errstr);
if (errstr != NULL) if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr)); sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
#ifdef HAVE_FEXECVE #ifdef HAVE_FEXECVE
@@ -740,7 +746,7 @@ command_info_to_details(char * const info[], struct command_details *details)
case 'n': case 'n':
if (strncmp("nice=", info[i], sizeof("nice=") - 1) == 0) { if (strncmp("nice=", info[i], sizeof("nice=") - 1) == 0) {
cp = info[i] + sizeof("nice=") - 1; cp = info[i] + sizeof("nice=") - 1;
details->priority = sudo_strtonum(cp, INT_MIN, INT_MAX, details->priority = (int)sudo_strtonum(cp, INT_MIN, INT_MAX,
&errstr); &errstr);
if (errstr != NULL) if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr)); sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
@@ -840,7 +846,7 @@ command_info_to_details(char * const info[], struct command_details *details)
SET_FLAG("sudoedit_follow=", CD_SUDOEDIT_FOLLOW) SET_FLAG("sudoedit_follow=", CD_SUDOEDIT_FOLLOW)
if (strncmp("sudoedit_nfiles=", info[i], sizeof("sudoedit_nfiles=") - 1) == 0) { if (strncmp("sudoedit_nfiles=", info[i], sizeof("sudoedit_nfiles=") - 1) == 0) {
cp = info[i] + sizeof("sudoedit_nfiles=") - 1; cp = info[i] + sizeof("sudoedit_nfiles=") - 1;
details->nfiles = sudo_strtonum(cp, 1, INT_MAX, details->nfiles = (int)sudo_strtonum(cp, 1, INT_MAX,
&errstr); &errstr);
if (errstr != NULL) if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr)); sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
@@ -850,7 +856,8 @@ command_info_to_details(char * const info[], struct command_details *details)
case 't': case 't':
if (strncmp("timeout=", info[i], sizeof("timeout=") - 1) == 0) { if (strncmp("timeout=", info[i], sizeof("timeout=") - 1) == 0) {
cp = info[i] + sizeof("timeout=") - 1; cp = info[i] + sizeof("timeout=") - 1;
details->timeout = sudo_strtonum(cp, 0, INT_MAX, &errstr); details->timeout =
(unsigned int)sudo_strtonum(cp, 0, UINT_MAX, &errstr);
if (errstr != NULL) if (errstr != NULL)
sudo_fatalx(U_("%s: %s"), info[i], U_(errstr)); sudo_fatalx(U_("%s: %s"), info[i], U_(errstr));
SET(details->flags, CD_SET_TIMEOUT); SET(details->flags, CD_SET_TIMEOUT);

View File

@@ -191,7 +191,7 @@ struct command_details {
mode_t umask; mode_t umask;
int argc; int argc;
int priority; int priority;
int timeout; unsigned int timeout;
int closefrom; int closefrom;
int flags; int flags;
int execfd; int execfd;

View File

@@ -84,7 +84,7 @@ set_tmpdir(const struct sudo_cred *user_cred)
saved_cred.ngroups = getgroups(0, NULL); // -V575 saved_cred.ngroups = getgroups(0, NULL); // -V575
if (saved_cred.ngroups > 0) { if (saved_cred.ngroups > 0) {
saved_cred.groups = saved_cred.groups =
reallocarray(NULL, saved_cred.ngroups, sizeof(GETGROUPS_T)); reallocarray(NULL, (size_t)saved_cred.ngroups, sizeof(GETGROUPS_T));
if (saved_cred.groups == NULL) { if (saved_cred.groups == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false); debug_return_bool(false);
@@ -149,7 +149,7 @@ sudo_edit_mktemp(const char *ofile, char **tfile)
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1); debug_return_int(-1);
} }
tfd = mkstemps(*tfile, suff ? strlen(suff) : 0); tfd = mkstemps(*tfile, suff ? (int)strlen(suff) : 0);
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
"%s -> %s, fd %d", ofile, *tfile, tfd); "%s -> %s, fd %d", ofile, *tfile, tfd);
debug_return_int(tfd); debug_return_int(tfd);
@@ -687,7 +687,7 @@ sudo_edit(struct command_details *command_details,
} }
/* Copy editor files to temporaries. */ /* Copy editor files to temporaries. */
tf = calloc(nfiles, sizeof(*tf)); tf = calloc((size_t)nfiles, sizeof(*tf));
if (tf == NULL) { if (tf == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto cleanup; goto cleanup;
@@ -707,7 +707,7 @@ sudo_edit(struct command_details *command_details,
* to create a new argv. * to create a new argv.
*/ */
nargc = editor_argc + nfiles; nargc = editor_argc + nfiles;
nargv = reallocarray(NULL, nargc + 1, sizeof(char *)); nargv = reallocarray(NULL, (size_t)nargc + 1, sizeof(char *));
if (nargv == NULL) { if (nargv == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto cleanup; goto cleanup;

View File

@@ -95,8 +95,8 @@ struct io_buffer {
struct sudo_event *revent; struct sudo_event *revent;
struct sudo_event *wevent; struct sudo_event *wevent;
sudo_io_action_t action; sudo_io_action_t action;
int len; /* buffer length (how much produced) */ unsigned int len; /* buffer length (how much produced) */
int off; /* write position (how much already consumed) */ unsigned int off; /* write position (how much already consumed) */
char buf[64 * 1024]; char buf[64 * 1024];
}; };
SLIST_HEAD(io_buffer_list, io_buffer); SLIST_HEAD(io_buffer_list, io_buffer);

View File

@@ -90,7 +90,7 @@ static char **
copy_vector(char * const *src) copy_vector(char * const *src)
{ {
char **copy; char **copy;
int i, len = 0; size_t i, len = 0;
debug_decl(copy_vector, SUDO_DEBUG_EXEC); debug_decl(copy_vector, SUDO_DEBUG_EXEC);
if (src != NULL) { if (src != NULL) {
@@ -141,7 +141,7 @@ resolve_path(const char *cmnd, char *out_cmnd, size_t out_size)
endp = cp + strlen(cp); endp = cp + strlen(cp);
while (cp < endp) { while (cp < endp) {
char *colon = strchr(cp, ':'); char *colon = strchr(cp, ':');
dirlen = colon ? (colon - cp) : (endp - cp); dirlen = colon ? (int)(colon - cp) : (int)(endp - cp);
if (dirlen == 0) { if (dirlen == 0) {
/* empty PATH component is the same as "." */ /* empty PATH component is the same as "." */
len = snprintf(path, sizeof(path), "./%s", cmnd); len = snprintf(path, sizeof(path), "./%s", cmnd);
@@ -265,12 +265,12 @@ exec_wrapper(const char *cmnd, char * const argv[], char * const envp[],
for (argc = 0; argv[argc] != NULL; argc++) for (argc = 0; argv[argc] != NULL; argc++)
continue; continue;
shargv = sudo_mmap_allocarray(argc + 2, sizeof(char *)); shargv = sudo_mmap_allocarray((size_t)argc + 2, sizeof(char *));
if (shargv == NULL) if (shargv == NULL)
goto bad; goto bad;
shargv[0] = "sh"; shargv[0] = "sh";
shargv[1] = ncmnd; shargv[1] = ncmnd;
memcpy(shargv + 2, nargv + 1, argc * sizeof(char *)); memcpy(shargv + 2, nargv + 1, (size_t)argc * sizeof(char *));
((sudo_fn_execve_t)fn)(_PATH_SUDO_BSHELL, (char **)shargv, nenvp); ((sudo_fn_execve_t)fn)(_PATH_SUDO_BSHELL, (char **)shargv, nenvp);
sudo_mmap_free(shargv); sudo_mmap_free(shargv);
} }
@@ -311,7 +311,7 @@ execl_wrapper(int type, const char *name, const char *arg, va_list ap)
while (va_arg(ap2, char *) != NULL) while (va_arg(ap2, char *) != NULL)
argc++; argc++;
va_end(ap2); va_end(ap2);
argv = sudo_mmap_allocarray(argc + 1, sizeof(char *)); argv = sudo_mmap_allocarray((size_t)argc + 1, sizeof(char *));
if (argv == NULL) if (argv == NULL)
debug_return_int(-1); debug_return_int(-1);

View File

@@ -85,7 +85,7 @@ send_req(int sock, const void *buf, size_t len)
continue; continue;
debug_return_bool(false); debug_return_bool(false);
} }
len -= nwritten; len -= (size_t)nwritten;
cp += nwritten; cp += nwritten;
} while (len > 0); } while (len > 0);
@@ -115,7 +115,7 @@ send_client_hello(int sock)
goto done; goto done;
} }
/* Wire message size is used for length encoding, precedes message. */ /* Wire message size is used for length encoding, precedes message. */
msg_len = len; msg_len = len & 0xffffffff;
len += sizeof(msg_len); len += sizeof(msg_len);
if ((buf = sudo_mmap_alloc(len)) == NULL) { if ((buf = sudo_mmap_alloc(len)) == NULL) {
@@ -196,7 +196,7 @@ recv_intercept_response(int fd)
"error reading response"); "error reading response");
goto done; goto done;
default: default:
rem -= nread; rem -= (uint32_t)nread;
cp += nread; cp += nread;
break; break;
} }
@@ -248,7 +248,7 @@ sudo_interposer_init(void)
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, "%s", *p); sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, "%s", *p);
fd = sudo_strtonum(fdstr, 0, INT_MAX, &errstr); fd = (int)sudo_strtonum(fdstr, 0, INT_MAX, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"invalid SUDO_INTERCEPT_FD: %s: %s", fdstr, errstr); "invalid SUDO_INTERCEPT_FD: %s: %s", fdstr, errstr);
@@ -280,7 +280,7 @@ sudo_interposer_init(void)
if (res->type_case == INTERCEPT_RESPONSE__TYPE_HELLO_RESP) { if (res->type_case == INTERCEPT_RESPONSE__TYPE_HELLO_RESP) {
intercept_token.u64[0] = res->u.hello_resp->token_lo; intercept_token.u64[0] = res->u.hello_resp->token_lo;
intercept_token.u64[1] = res->u.hello_resp->token_hi; intercept_token.u64[1] = res->u.hello_resp->token_hi;
intercept_port = res->u.hello_resp->portno; intercept_port = (in_port_t)res->u.hello_resp->portno;
log_only = res->u.hello_resp->log_only; log_only = res->u.hello_resp->log_only;
} else { } else {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
@@ -340,7 +340,7 @@ send_policy_check_req(int sock, const char *cmnd, char * const argv[],
goto done; goto done;
} }
/* Wire message size is used for length encoding, precedes message. */ /* Wire message size is used for length encoding, precedes message. */
msg_len = len; msg_len = len & 0xffffffff;
len += sizeof(msg_len); len += sizeof(msg_len);
if ((buf = sudo_mmap_alloc(len)) == NULL) { if ((buf = sudo_mmap_alloc(len)) == NULL) {

View File

@@ -222,7 +222,7 @@ restart:
} }
if (timeout > 0) if (timeout > 0)
alarm(timeout); alarm((unsigned int)timeout);
pass = getln(input, buf, sizeof(buf), feedback, &errval); pass = getln(input, buf, sizeof(buf), feedback, &errval);
alarm(0); alarm(0);
save_errno = errno; save_errno = errno;

View File

@@ -133,7 +133,7 @@ get_process_ttyname(char *name, size_t namelen)
if (rc != -1) { if (rc != -1) {
if ((dev_t)ki_proc->sudo_kp_tdev != (dev_t)-1) { if ((dev_t)ki_proc->sudo_kp_tdev != (dev_t)-1) {
errno = serrno; errno = serrno;
ret = sudo_ttyname_dev(ki_proc->sudo_kp_tdev, name, namelen); ret = sudo_ttyname_dev((dev_t)ki_proc->sudo_kp_tdev, name, namelen);
if (ret == NULL) { if (ret == NULL) {
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO, sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"unable to map device number %lu to name", "unable to map device number %lu to name",
@@ -223,7 +223,7 @@ get_process_ttyname(char *name, size_t namelen)
*/ */
if ((fd = open(path, O_RDONLY | O_NOFOLLOW)) != -1) { if ((fd = open(path, O_RDONLY | O_NOFOLLOW)) != -1) {
cp = buf; cp = buf;
while ((nread = read(fd, cp, buf + sizeof(buf) - cp)) != 0) { while ((nread = read(fd, cp, sizeof(buf) - (size_t)(cp - buf))) != 0) {
if (nread == -1) { if (nread == -1) {
if (errno == EAGAIN || errno == EINTR) if (errno == EAGAIN || errno == EINTR)
continue; continue;
@@ -233,7 +233,7 @@ get_process_ttyname(char *name, size_t namelen)
if (cp >= buf + sizeof(buf)) if (cp >= buf + sizeof(buf))
break; break;
} }
if (nread == 0 && memchr(buf, '\0', cp - buf) == NULL) { if (nread == 0 && memchr(buf, '\0', (size_t)(cp - buf)) == NULL) {
/* /*
* Field 7 is the tty dev (0 if no tty). * Field 7 is the tty dev (0 if no tty).
* Since the process name at field 2 "(comm)" may include * Since the process name at field 2 "(comm)" may include
@@ -251,8 +251,8 @@ get_process_ttyname(char *name, size_t namelen)
*ep = '\0'; *ep = '\0';
field++; field++;
if (field == 7) { if (field == 7) {
int tty_nr = sudo_strtonum(cp, INT_MIN, INT_MAX, int tty_nr = (int)sudo_strtonum(cp, INT_MIN,
&errstr); INT_MAX, &errstr);
if (errstr) { if (errstr) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"%s: tty device %s: %s", path, cp, errstr); "%s: tty device %s: %s", path, cp, errstr);
@@ -272,7 +272,8 @@ get_process_ttyname(char *name, size_t namelen)
break; break;
} }
if (field == 3) { if (field == 3) {
ppid = sudo_strtonum(cp, INT_MIN, INT_MAX, NULL); ppid =
(int)sudo_strtonum(cp, INT_MIN, INT_MAX, NULL);
} }
cp = ep + 1; cp = ep + 1;
} }