Make the debug subsystem unsigned.

It was already unsigned in sudoers but not in the front-end or the
python plugin.  Making this consistent resolves a lot of -Wconversion
warnings.  Also clean up some other -Wconversion warnings in sudo_debug.c.
This commit is contained in:
Todd C. Miller
2023-07-01 16:14:50 -06:00
parent 04c7e910ef
commit b926df1df2
7 changed files with 121 additions and 104 deletions

View File

@@ -107,13 +107,13 @@ struct sudo_conf_debug_file_list;
#ifdef HAVE___FUNC__ #ifdef HAVE___FUNC__
# define debug_decl_func(funcname) # define debug_decl_func(funcname)
# define debug_decl_vars(funcname, subsys) \ # define debug_decl_vars(funcname, subsys) \
const int sudo_debug_subsys = (subsys) const unsigned int sudo_debug_subsys = (subsys)
#else #else
# define debug_decl_func(funcname) \ # define debug_decl_func(funcname) \
const char __func__[] = #funcname; const char __func__[] = #funcname;
# define debug_decl_vars(funcname, subsys) \ # define debug_decl_vars(funcname, subsys) \
debug_decl_func(funcname) \ debug_decl_func(funcname) \
const int sudo_debug_subsys = (subsys) const unsigned int sudo_debug_subsys = (subsys)
#endif #endif
#define debug_decl(funcname, subsys) \ #define debug_decl(funcname, subsys) \
debug_decl_vars((funcname), (subsys)); \ debug_decl_vars((funcname), (subsys)); \
@@ -247,33 +247,33 @@ struct sudo_conf_debug_file_list;
sudo_debug_write2(fd, NULL, NULL, 0, (str), (len), (errnum)) sudo_debug_write2(fd, NULL, NULL, 0, (str), (len), (errnum))
sudo_dso_public int sudo_debug_deregister_v1(int instance_id); sudo_dso_public int sudo_debug_deregister_v1(int instance_id);
sudo_dso_public void sudo_debug_enter_v1(const char *func, const char *file, int line, int subsys); sudo_dso_public void sudo_debug_enter_v1(const char *func, const char *file, int line, unsigned int subsys);
sudo_dso_public void sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *const envp[]); sudo_dso_public void sudo_debug_execve2_v1(unsigned int level, const char *path, char *const argv[], char *const envp[]);
sudo_dso_public void sudo_debug_exit_v1(const char *func, const char *file, int line, int subsys); sudo_dso_public void sudo_debug_exit_v1(const char *func, const char *file, int line, unsigned int subsys);
sudo_dso_public void sudo_debug_exit_bool_v1(const char *func, const char *file, int line, int subsys, bool ret); sudo_dso_public void sudo_debug_exit_bool_v1(const char *func, const char *file, int line, unsigned int subsys, bool ret);
sudo_dso_public void sudo_debug_exit_int_v1(const char *func, const char *file, int line, int subsys, int ret); sudo_dso_public void sudo_debug_exit_int_v1(const char *func, const char *file, int line, unsigned int subsys, int ret);
sudo_dso_public void sudo_debug_exit_long_v1(const char *func, const char *file, int line, int subsys, long ret); sudo_dso_public void sudo_debug_exit_long_v1(const char *func, const char *file, int line, unsigned int subsys, long ret);
sudo_dso_public void sudo_debug_exit_ptr_v1(const char *func, const char *file, int line, int subsys, const void *ret); sudo_dso_public void sudo_debug_exit_ptr_v1(const char *func, const char *file, int line, unsigned int subsys, const void *ret);
sudo_dso_public void sudo_debug_exit_id_t_v1(const char *func, const char *file, int line, int subsys, id_t ret); sudo_dso_public void sudo_debug_exit_id_t_v1(const char *func, const char *file, int line, unsigned int subsys, id_t ret);
sudo_dso_public void sudo_debug_exit_size_t_v1(const char *func, const char *file, int line, int subsys, size_t ret); sudo_dso_public void sudo_debug_exit_size_t_v1(const char *func, const char *file, int line, unsigned int subsys, size_t ret);
sudo_dso_public void sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line, int subsys, ssize_t ret); sudo_dso_public void sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line, unsigned int subsys, ssize_t ret);
sudo_dso_public void sudo_debug_exit_str_v1(const char *func, const char *file, int line, int subsys, const char *ret); sudo_dso_public void sudo_debug_exit_str_v1(const char *func, const char *file, int line, unsigned int subsys, const char *ret);
sudo_dso_public void sudo_debug_exit_str_masked_v1(const char *func, const char *file, int line, int subsys, const char *ret); sudo_dso_public void sudo_debug_exit_str_masked_v1(const char *func, const char *file, int line, unsigned int subsys, const char *ret);
sudo_dso_public void sudo_debug_exit_time_t_v1(const char *func, const char *file, int line, int subsys, time_t ret); sudo_dso_public void sudo_debug_exit_time_t_v1(const char *func, const char *file, int line, unsigned int subsys, time_t ret);
sudo_dso_public pid_t sudo_debug_fork_v1(void); sudo_dso_public pid_t sudo_debug_fork_v1(void);
sudo_dso_public int sudo_debug_get_active_instance_v1(void); sudo_dso_public int sudo_debug_get_active_instance_v1(void);
sudo_dso_public int sudo_debug_get_fds_v1(unsigned char **fds); sudo_dso_public int sudo_debug_get_fds_v1(unsigned char **fds);
sudo_dso_public int sudo_debug_get_instance_v1(const char *program); sudo_dso_public int sudo_debug_get_instance_v1(const char *program);
sudo_dso_public int sudo_debug_parse_flags_v1(struct sudo_conf_debug_file_list *debug_files, const char *entry); sudo_dso_public int sudo_debug_parse_flags_v1(struct sudo_conf_debug_file_list *debug_files, const char *entry);
sudo_dso_public void sudo_debug_printf2_v1(const char *func, const char *file, int line, int level, const char *fmt, ...) sudo_printf0like(5, 6); sudo_dso_public void sudo_debug_printf2_v1(const char *func, const char *file, int line, unsigned int level, const char *fmt, ...) sudo_printf0like(5, 6);
sudo_dso_public void sudo_debug_printf_nvm_v1(int pri, const char *fmt, ...) sudo_printf0like(2, 3); sudo_dso_public void sudo_debug_printf_nvm_v1(int pri, const char *fmt, ...) sudo_printf0like(2, 3);
sudo_dso_public int sudo_debug_register_v1(const char *program, const char *const subsystems[], unsigned int ids[], struct sudo_conf_debug_file_list *debug_files); sudo_dso_public int sudo_debug_register_v1(const char *program, const char *const subsystems[], unsigned int ids[], struct sudo_conf_debug_file_list *debug_files);
sudo_dso_public int sudo_debug_register_v2(const char *program, const char *const subsystems[], unsigned int ids[], struct sudo_conf_debug_file_list *debug_files, int minfd); sudo_dso_public int sudo_debug_register_v2(const char *program, const char *const subsystems[], unsigned int ids[], struct sudo_conf_debug_file_list *debug_files, int minfd);
sudo_dso_public int sudo_debug_set_active_instance_v1(int inst); sudo_dso_public int sudo_debug_set_active_instance_v1(int inst);
sudo_dso_public void sudo_debug_update_fd_v1(int ofd, int nfd); sudo_dso_public void sudo_debug_update_fd_v1(int ofd, int nfd);
sudo_dso_public void sudo_debug_vprintf2_v1(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) sudo_printf0like(5, 0); sudo_dso_public void sudo_debug_vprintf2_v1(const char *func, const char *file, int line, unsigned int level, const char *fmt, va_list ap) sudo_printf0like(5, 0);
sudo_dso_public void sudo_debug_write2_v1(int fd, const char *func, const char *file, int line, const char *str, int len, int errnum); sudo_dso_public void sudo_debug_write2_v1(int fd, const char *func, const char *file, int line, const char *str, unsigned int len, int errnum);
sudo_dso_public bool sudo_debug_needed_v1(int level); sudo_dso_public bool sudo_debug_needed_v1(unsigned int level);
#define sudo_debug_needed(level) sudo_debug_needed_v1((level)|sudo_debug_subsys) #define sudo_debug_needed(level) sudo_debug_needed_v1((level)|sudo_debug_subsys)
#define sudo_debug_deregister(_a) sudo_debug_deregister_v1((_a)) #define sudo_debug_deregister(_a) sudo_debug_deregister_v1((_a))

View File

@@ -409,7 +409,7 @@ sudo_debug_deregister_v1(int idx)
return -1; /* already deregistered */ return -1; /* already deregistered */
if (--instance->refcnt != 0) if (--instance->refcnt != 0)
return instance->refcnt; /* ref held by other caller */ return (int)instance->refcnt; /* ref held by other caller */
/* Free up instance data, note that subsystems[] is owned by caller. */ /* Free up instance data, note that subsystems[] is owned by caller. */
sudo_debug_instances[idx] = NULL; sudo_debug_instances[idx] = NULL;
@@ -497,7 +497,7 @@ sudo_debug_fork_v1(void)
void void
sudo_debug_enter_v1(const char *func, const char *file, int line, sudo_debug_enter_v1(const char *func, const char *file, int line,
int subsys) unsigned int subsys)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"-> %s @ %s:%d", func, file, line); "-> %s @ %s:%d", func, file, line);
@@ -505,7 +505,7 @@ sudo_debug_enter_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_v1(const char *func, const char *file, int line, sudo_debug_exit_v1(const char *func, const char *file, int line,
int subsys) unsigned int subsys)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d", func, file, line); "<- %s @ %s:%d", func, file, line);
@@ -513,7 +513,7 @@ sudo_debug_exit_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_int_v1(const char *func, const char *file, int line, sudo_debug_exit_int_v1(const char *func, const char *file, int line,
int subsys, int ret) unsigned int subsys, int ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %d", func, file, line, ret); "<- %s @ %s:%d := %d", func, file, line, ret);
@@ -521,7 +521,7 @@ sudo_debug_exit_int_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_long_v1(const char *func, const char *file, int line, sudo_debug_exit_long_v1(const char *func, const char *file, int line,
int subsys, long ret) unsigned int subsys, long ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %ld", func, file, line, ret); "<- %s @ %s:%d := %ld", func, file, line, ret);
@@ -529,7 +529,7 @@ sudo_debug_exit_long_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_id_t_v1(const char *func, const char *file, int line, sudo_debug_exit_id_t_v1(const char *func, const char *file, int line,
int subsys, id_t ret) unsigned int subsys, id_t ret)
{ {
#if SIZEOF_ID_T == 8 #if SIZEOF_ID_T == 8
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
@@ -542,7 +542,7 @@ sudo_debug_exit_id_t_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_size_t_v1(const char *func, const char *file, int line, sudo_debug_exit_size_t_v1(const char *func, const char *file, int line,
int subsys, size_t ret) unsigned int subsys, size_t ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %zu", func, file, line, ret); "<- %s @ %s:%d := %zu", func, file, line, ret);
@@ -550,7 +550,7 @@ sudo_debug_exit_size_t_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line, sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line,
int subsys, ssize_t ret) unsigned int subsys, ssize_t ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %zd", func, file, line, ret); "<- %s @ %s:%d := %zd", func, file, line, ret);
@@ -558,7 +558,7 @@ sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_time_t_v1(const char *func, const char *file, int line, sudo_debug_exit_time_t_v1(const char *func, const char *file, int line,
int subsys, time_t ret) unsigned int subsys, time_t ret)
{ {
#if SIZEOF_TIME_T == 8 #if SIZEOF_TIME_T == 8
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
@@ -571,7 +571,7 @@ sudo_debug_exit_time_t_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_bool_v1(const char *func, const char *file, int line, sudo_debug_exit_bool_v1(const char *func, const char *file, int line,
int subsys, bool ret) unsigned int subsys, bool ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %s", func, file, line, ret ? "true" : "false"); "<- %s @ %s:%d := %s", func, file, line, ret ? "true" : "false");
@@ -579,7 +579,7 @@ sudo_debug_exit_bool_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_str_v1(const char *func, const char *file, int line, sudo_debug_exit_str_v1(const char *func, const char *file, int line,
int subsys, const char *ret) unsigned int subsys, const char *ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %s", func, file, line, ret ? ret : "(null)"); "<- %s @ %s:%d := %s", func, file, line, ret ? ret : "(null)");
@@ -587,18 +587,19 @@ sudo_debug_exit_str_v1(const char *func, const char *file, int line,
void void
sudo_debug_exit_str_masked_v1(const char *func, const char *file, int line, sudo_debug_exit_str_masked_v1(const char *func, const char *file, int line,
int subsys, const char *ret) unsigned int subsys, const char *ret)
{ {
static const char stars[] = "********************************************************************************"; static const char stars[] = "********************************************************************************";
int len = ret ? strlen(ret) : sizeof("(null)") - 1; const size_t len = ret ? strlen(ret) : sizeof("(null)") - 1;
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %.*s", func, file, line, len, ret ? stars : "(null)"); "<- %s @ %s:%d := %.*s", func, file, line, (int)len,
ret ? stars : "(null)");
} }
void void
sudo_debug_exit_ptr_v1(const char *func, const char *file, int line, sudo_debug_exit_ptr_v1(const char *func, const char *file, int line,
int subsys, const void *ret) unsigned int subsys, const void *ret)
{ {
sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE, sudo_debug_printf2(NULL, NULL, 0, subsys | SUDO_DEBUG_TRACE,
"<- %s @ %s:%d := %p", func, file, line, ret); "<- %s @ %s:%d := %p", func, file, line, ret);
@@ -606,7 +607,7 @@ sudo_debug_exit_ptr_v1(const char *func, const char *file, int line,
void void
sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno, sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno,
const char *str, int len, int errnum) const char *str, unsigned int len, int errnum)
{ {
char numbuf[(((sizeof(int) * 8) + 2) / 3) + 2]; char numbuf[(((sizeof(int) * 8) + 2) / 3) + 2];
char timebuf[64]; char timebuf[64];
@@ -644,7 +645,7 @@ sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno,
/* Add string, trimming any trailing newlines. */ /* Add string, trimming any trailing newlines. */
while (len > 0 && str[len - 1] == '\n') while (len > 0 && str[len - 1] == '\n')
len--; len--;
if (len > 0) { if (len != 0) {
iov[iovcnt].iov_base = (char *)str; iov[iovcnt].iov_base = (char *)str;
iov[iovcnt].iov_len = len; iov[iovcnt].iov_len = len;
iovcnt++; iovcnt++;
@@ -652,7 +653,7 @@ sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno,
/* Append error string if errno is specified. */ /* Append error string if errno is specified. */
if (errnum) { if (errnum) {
if (len > 0) { if (len != 0) {
iov[iovcnt].iov_base = (char *)": "; iov[iovcnt].iov_base = (char *)": ";
iov[iovcnt].iov_len = 2; iov[iovcnt].iov_len = 2;
iovcnt++; iovcnt++;
@@ -696,7 +697,7 @@ sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno,
} }
bool bool
sudo_debug_needed_v1(int level) sudo_debug_needed_v1(unsigned int level)
{ {
unsigned int subsys; unsigned int subsys;
int pri; int pri;
@@ -708,8 +709,8 @@ sudo_debug_needed_v1(int level)
goto out; goto out;
/* Extract priority and subsystem from level. */ /* Extract priority and subsystem from level. */
pri = SUDO_DEBUG_PRI(level); pri = (int)SUDO_DEBUG_PRI(level);
subsys = (unsigned int)SUDO_DEBUG_SUBSYS(level); subsys = SUDO_DEBUG_SUBSYS(level);
if (sudo_debug_active_instance > sudo_debug_last_instance) if (sudo_debug_active_instance > sudo_debug_last_instance)
goto out; goto out;
@@ -731,10 +732,10 @@ out:
} }
void void
sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno, int level, sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno,
const char *fmt, va_list ap) unsigned int level, const char *fmt, va_list ap)
{ {
int buflen, pri, saved_errno = errno; int pri, saved_errno = errno;
unsigned int subsys; unsigned int subsys;
char static_buf[1024], *buf = static_buf; char static_buf[1024], *buf = static_buf;
struct sudo_debug_instance *instance; struct sudo_debug_instance *instance;
@@ -745,9 +746,16 @@ sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno, int level
goto out; goto out;
/* Extract priority and subsystem from level. */ /* Extract priority and subsystem from level. */
pri = SUDO_DEBUG_PRI(level); pri = (int)SUDO_DEBUG_PRI(level);
subsys = SUDO_DEBUG_SUBSYS(level); subsys = SUDO_DEBUG_SUBSYS(level);
/* Disable extra info if SUDO_DEBUG_LINENO is not enabled. */
if (!ISSET(level, SUDO_DEBUG_LINENO)) {
func = NULL;
file = NULL;
lineno = 0;
}
/* Find matching instance. */ /* Find matching instance. */
if (sudo_debug_active_instance > sudo_debug_last_instance) { if (sudo_debug_active_instance > sudo_debug_last_instance) {
sudo_warnx_nodebug("%s: invalid instance ID %d, max %d", sudo_warnx_nodebug("%s: invalid instance ID %d, max %d",
@@ -764,31 +772,36 @@ sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno, int level
SLIST_FOREACH(output, &instance->outputs, entries) { SLIST_FOREACH(output, &instance->outputs, entries) {
/* Make sure we want debug info at this level. */ /* Make sure we want debug info at this level. */
if (subsys <= instance->max_subsystem && output->settings[subsys] >= pri) { if (subsys <= instance->max_subsystem && output->settings[subsys] >= pri) {
int errcode, buflen = 0;
va_list ap2; va_list ap2;
/* Operate on a copy of ap to support multiple outputs. */ if (fmt != NULL) {
va_copy(ap2, ap); /* Operate on a copy of ap to support multiple outputs. */
buflen = fmt ? vsnprintf(static_buf, sizeof(static_buf), fmt, ap2) : 0; va_copy(ap2, ap);
va_end(ap2); buflen = vsnprintf(static_buf, sizeof(static_buf), fmt, ap2);
if (buflen >= ssizeof(static_buf)) { va_end(ap2);
va_list ap3; if (buflen < 0) {
sudo_warnx_nodebug("%s: invalid format string \"%s\"",
/* Not enough room in static buf, allocate dynamically. */ __func__, fmt);
va_copy(ap3, ap); buflen = 0;
buflen = vasprintf(&buf, fmt, ap3); } else if (buflen >= ssizeof(static_buf)) {
va_end(ap3); /* Not enough room in static buf, allocate dynamically. */
} va_copy(ap2, ap);
if (buflen != -1) { buflen = vasprintf(&buf, fmt, ap2);
int errcode = ISSET(level, SUDO_DEBUG_ERRNO) ? saved_errno : 0; if (buflen == -1) {
if (ISSET(level, SUDO_DEBUG_LINENO)) buf = static_buf;
sudo_debug_write2(output->fd, func, file, lineno, buf, buflen, errcode); buflen = (int)strlen(buf);
else }
sudo_debug_write2(output->fd, NULL, NULL, 0, buf, buflen, errcode); va_end(ap2);
if (buf != static_buf) {
free(buf);
buf = static_buf;
} }
} }
errcode = ISSET(level, SUDO_DEBUG_ERRNO) ? saved_errno : 0;
sudo_debug_write2(output->fd, func, file, lineno, buf,
(unsigned int)buflen, errcode);
if (buf != static_buf) {
free(buf);
buf = static_buf;
}
} }
} }
out: out:
@@ -808,8 +821,8 @@ sudo_debug_printf_nvm_v1(int pri, const char *fmt, ...)
#endif /* NO_VARIADIC_MACROS */ #endif /* NO_VARIADIC_MACROS */
void void
sudo_debug_printf2_v1(const char *func, const char *file, int lineno, int level, sudo_debug_printf2_v1(const char *func, const char *file, int lineno,
const char *fmt, ...) unsigned int level, const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -821,22 +834,23 @@ sudo_debug_printf2_v1(const char *func, const char *file, int lineno, int level,
#define EXEC_PREFIX "exec " #define EXEC_PREFIX "exec "
void void
sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *const envp[]) sudo_debug_execve2_v1(unsigned int level, const char *path, char *const argv[],
char *const envp[])
{ {
int buflen, pri, saved_errno = errno; int pri, saved_errno = errno;
unsigned int subsys; unsigned int subsys;
struct sudo_debug_instance *instance; struct sudo_debug_instance *instance;
struct sudo_debug_output *output; struct sudo_debug_output *output;
char * const *av; char * const *av;
char *cp, static_buf[4096], *buf = static_buf; char *cp, static_buf[4096], *buf = static_buf;
size_t plen; size_t buflen, plen;
debug_decl_func(sudo_debug_execve2); debug_decl_func(sudo_debug_execve2);
if (sudo_debug_active_instance == -1 || path == NULL) if (sudo_debug_active_instance == -1 || path == NULL)
goto out; goto out;
/* Extract priority and subsystem from level. */ /* Extract priority and subsystem from level. */
pri = SUDO_DEBUG_PRI(level); pri = (int)SUDO_DEBUG_PRI(level);
subsys = SUDO_DEBUG_SUBSYS(level); subsys = SUDO_DEBUG_SUBSYS(level);
/* Find matching instance. */ /* Find matching instance. */
@@ -880,7 +894,7 @@ sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *con
buflen += strlen(*av) + 1; buflen += strlen(*av) + 1;
buflen--; buflen--;
} }
if (buflen >= ssizeof(static_buf)) { if (buflen >= sizeof(static_buf)) {
buf = malloc(buflen + 1); buf = malloc(buflen + 1);
if (buf == NULL) if (buf == NULL)
goto out; goto out;
@@ -919,7 +933,7 @@ sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *con
*cp = '\0'; *cp = '\0';
sudo_debug_write(output->fd, buf, buflen, 0); sudo_debug_write(output->fd, buf, (unsigned int)buflen, 0);
if (buf != static_buf) { if (buf != static_buf) {
free(buf); free(buf);
buf = static_buf; buf = static_buf;
@@ -1037,91 +1051,91 @@ sudo_debug_fork_v1(void)
void void
sudo_debug_enter_v1(const char *func, const char *file, int line, sudo_debug_enter_v1(const char *func, const char *file, int line,
int subsys) unsigned int subsys)
{ {
} }
void void
sudo_debug_exit_v1(const char *func, const char *file, int line, sudo_debug_exit_v1(const char *func, const char *file, int line,
int subsys) unsigned int subsys)
{ {
} }
void void
sudo_debug_exit_int_v1(const char *func, const char *file, int line, sudo_debug_exit_int_v1(const char *func, const char *file, int line,
int subsys, int ret) unsigned int subsys, int ret)
{ {
} }
void void
sudo_debug_exit_long_v1(const char *func, const char *file, int line, sudo_debug_exit_long_v1(const char *func, const char *file, int line,
int subsys, long ret) unsigned int subsys, long ret)
{ {
} }
void void
sudo_debug_exit_id_t_v1(const char *func, const char *file, int line, sudo_debug_exit_id_t_v1(const char *func, const char *file, int line,
int subsys, id_t ret) unsigned int subsys, id_t ret)
{ {
} }
void void
sudo_debug_exit_size_t_v1(const char *func, const char *file, int line, sudo_debug_exit_size_t_v1(const char *func, const char *file, int line,
int subsys, size_t ret) unsigned int subsys, size_t ret)
{ {
} }
void void
sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line, sudo_debug_exit_ssize_t_v1(const char *func, const char *file, int line,
int subsys, ssize_t ret) unsigned int subsys, ssize_t ret)
{ {
} }
void void
sudo_debug_exit_time_t_v1(const char *func, const char *file, int line, sudo_debug_exit_time_t_v1(const char *func, const char *file, int line,
int subsys, time_t ret) unsigned int subsys, time_t ret)
{ {
} }
void void
sudo_debug_exit_bool_v1(const char *func, const char *file, int line, sudo_debug_exit_bool_v1(const char *func, const char *file, int line,
int subsys, bool ret) unsigned int subsys, bool ret)
{ {
} }
void void
sudo_debug_exit_str_v1(const char *func, const char *file, int line, sudo_debug_exit_str_v1(const char *func, const char *file, int line,
int subsys, const char *ret) unsigned int subsys, const char *ret)
{ {
} }
void void
sudo_debug_exit_str_masked_v1(const char *func, const char *file, int line, sudo_debug_exit_str_masked_v1(const char *func, const char *file, int line,
int subsys, const char *ret) unsigned int subsys, const char *ret)
{ {
} }
void void
sudo_debug_exit_ptr_v1(const char *func, const char *file, int line, sudo_debug_exit_ptr_v1(const char *func, const char *file, int line,
int subsys, const void *ret) unsigned int subsys, const void *ret)
{ {
} }
void void
sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno, sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno,
const char *str, int len, int errnum) const char *str, unsigned int len, int errnum)
{ {
} }
bool bool
sudo_debug_needed_v1(int level) sudo_debug_needed_v1(unsigned int level)
{ {
return false; return false;
} }
void void
sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno, int level, sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno,
const char *fmt, va_list ap) unsigned int level, const char *fmt, va_list ap)
{ {
} }
@@ -1133,13 +1147,14 @@ sudo_debug_printf_nvm_v1(int pri, const char *fmt, ...)
#endif /* NO_VARIADIC_MACROS */ #endif /* NO_VARIADIC_MACROS */
void void
sudo_debug_printf2_v1(const char *func, const char *file, int lineno, int level, sudo_debug_printf2_v1(const char *func, const char *file, int lineno,
const char *fmt, ...) unsigned int level, const char *fmt, ...)
{ {
} }
void void
sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *const envp[]) sudo_debug_execve2_v1(unsigned int level, const char *path, char *const argv[],
char *const envp[])
{ {
} }

View File

@@ -321,7 +321,7 @@ done:
static void static void
_py_debug_python_function(const char *class_name, const char *function_name, const char *message, _py_debug_python_function(const char *class_name, const char *function_name, const char *message,
PyObject *py_args, PyObject *py_kwargs, int subsystem_id) PyObject *py_args, PyObject *py_kwargs, unsigned int subsystem_id)
{ {
debug_decl_vars(_py_debug_python_function, subsystem_id); debug_decl_vars(_py_debug_python_function, subsystem_id);
@@ -373,7 +373,8 @@ _py_debug_python_function(const char *class_name, const char *function_name, con
void void
py_debug_python_call(const char *class_name, const char *function_name, py_debug_python_call(const char *class_name, const char *function_name,
PyObject *py_args, PyObject *py_kwargs, int subsystem_id) PyObject *py_args, PyObject *py_kwargs,
unsigned int subsystem_id)
{ {
debug_decl_vars(py_debug_python_call, subsystem_id); debug_decl_vars(py_debug_python_call, subsystem_id);
@@ -397,7 +398,7 @@ py_debug_python_call(const char *class_name, const char *function_name,
void void
py_debug_python_result(const char *class_name, const char *function_name, py_debug_python_result(const char *class_name, const char *function_name,
PyObject *py_result, int subsystem_id) PyObject *py_result, unsigned int subsystem_id)
{ {
if (py_result == NULL) { if (py_result == NULL) {
debug_decl_vars(py_debug_python_result, subsystem_id); debug_decl_vars(py_debug_python_result, subsystem_id);

View File

@@ -94,9 +94,10 @@ void py_object_set_attr_string(PyObject *py_object, const char *attr_name, const
PyObject *py_create_version(unsigned int version); PyObject *py_create_version(unsigned int version);
void py_debug_python_call(const char *class_name, const char *function_name, void py_debug_python_call(const char *class_name, const char *function_name,
PyObject *py_args, PyObject *py_kwargs, int subsystem_id); PyObject *py_args, PyObject *py_kwargs,
unsigned int subsystem_id);
void py_debug_python_result(const char *class_name, const char *function_name, void py_debug_python_result(const char *class_name, const char *function_name,
PyObject *py_args, int subsystem_id); PyObject *py_args, unsigned int subsystem_id);
void str_array_free(char ***array); void str_array_free(char ***array);

View File

@@ -27,7 +27,7 @@ PyObject *sudo_type_LogHandler;
static void static void
_debug_plugin(int log_level, const char *log_message) _debug_plugin(unsigned int log_level, const char *log_message)
{ {
debug_decl_vars(python_sudo_debug, PYTHON_DEBUG_PLUGIN); debug_decl_vars(python_sudo_debug, PYTHON_DEBUG_PLUGIN);
@@ -54,7 +54,7 @@ python_sudo_debug(PyObject *Py_UNUSED(py_self), PyObject *py_args)
debug_decl(python_sudo_debug, PYTHON_DEBUG_C_CALLS); debug_decl(python_sudo_debug, PYTHON_DEBUG_C_CALLS);
py_debug_python_call("sudo", "debug", py_args, NULL, PYTHON_DEBUG_C_CALLS); py_debug_python_call("sudo", "debug", py_args, NULL, PYTHON_DEBUG_C_CALLS);
int log_level = SUDO_DEBUG_DEBUG; unsigned int log_level = SUDO_DEBUG_DEBUG;
const char *log_message = NULL; const char *log_message = NULL;
if (!PyArg_ParseTuple(py_args, "is:sudo.debug", &log_level, &log_message)) { if (!PyArg_ParseTuple(py_args, "is:sudo.debug", &log_level, &log_message)) {
debug_return_ptr(NULL); debug_return_ptr(NULL);
@@ -65,7 +65,7 @@ python_sudo_debug(PyObject *Py_UNUSED(py_self), PyObject *py_args)
debug_return_ptr_pynone; debug_return_ptr_pynone;
} }
static int static unsigned int
_sudo_log_level_from_python(long level) _sudo_log_level_from_python(long level)
{ {
if (level >= 50) if (level >= 50)
@@ -99,7 +99,7 @@ _sudo_LogHandler__emit(PyObject *py_self, PyObject *py_args)
goto cleanup; goto cleanup;
} }
int sudo_loglevel = _sudo_log_level_from_python(python_loglevel); unsigned int sudo_loglevel = _sudo_log_level_from_python(python_loglevel);
py_message = PyObject_CallMethod(py_self, "format", "O", py_record); py_message = PyObject_CallMethod(py_self, "format", "O", py_record);
if (py_message == NULL) if (py_message == NULL)

View File

@@ -51,7 +51,7 @@ static const char *const python_subsystem_names[] = {
#define NUM_SUBSYSTEMS sizeof(python_subsystem_names) / sizeof(*python_subsystem_names) - 1 #define NUM_SUBSYSTEMS sizeof(python_subsystem_names) / sizeof(*python_subsystem_names) - 1
/* Subsystem IDs assigned at registration time. */ /* Subsystem IDs assigned at registration time. */
int python_subsystem_ids[NUM_SUBSYSTEMS]; unsigned int python_subsystem_ids[NUM_SUBSYSTEMS];
/* /*
* Parse the "filename flags,..." debug_flags entry and insert a new * Parse the "filename flags,..." debug_flags entry and insert a new
@@ -84,7 +84,7 @@ python_debug_register(const char *program,
if (debug_files != NULL && !TAILQ_EMPTY(debug_files)) { if (debug_files != NULL && !TAILQ_EMPTY(debug_files)) {
if (program != NULL) { if (program != NULL) {
instance = sudo_debug_register(program, python_subsystem_names, instance = sudo_debug_register(program, python_subsystem_names,
(unsigned int *)python_subsystem_ids, debug_files, -1); python_subsystem_ids, debug_files, -1);
} }
TAILQ_FOREACH_SAFE(debug_file, debug_files, entries, debug_next) { TAILQ_FOREACH_SAFE(debug_file, debug_files, entries, debug_next) {
TAILQ_REMOVE(debug_files, debug_file, entries); TAILQ_REMOVE(debug_files, debug_file, entries);

View File

@@ -25,7 +25,7 @@
* Sudo python plugin debug subsystems. * Sudo python plugin debug subsystems.
* Note that python_subsystem_ids[] is filled in at debug registration time. * Note that python_subsystem_ids[] is filled in at debug registration time.
*/ */
extern int python_subsystem_ids[]; extern unsigned int python_subsystem_ids[];
#define PYTHON_DEBUG_PY_CALLS (python_subsystem_ids[0]) #define PYTHON_DEBUG_PY_CALLS (python_subsystem_ids[0])
#define PYTHON_DEBUG_C_CALLS (python_subsystem_ids[1]) #define PYTHON_DEBUG_C_CALLS (python_subsystem_ids[1])
#define PYTHON_DEBUG_PLUGIN_LOAD (python_subsystem_ids[2]) #define PYTHON_DEBUG_PLUGIN_LOAD (python_subsystem_ids[2])