diff --git a/Makefile.in b/Makefile.in index 2290d2d0e..e809ab715 100644 --- a/Makefile.in +++ b/Makefile.in @@ -83,7 +83,7 @@ XGETTEXT_OPTS = -F -k_ -kN_ -kU_ --copyright-holder="Todd C. Miller" \ --flag sudo_lbuf_append_quoted:3:c-format --foreign-user # Default cppcheck options when run from the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -U__NBBY -DNSIG=64 all: config.status for d in $(SUBDIRS); do \ diff --git a/include/sudo_debug.h b/include/sudo_debug.h index 44193cd3f..4e5e8cfcc 100644 --- a/include/sudo_debug.h +++ b/include/sudo_debug.h @@ -20,6 +20,21 @@ #include #include "sudo_queue.h" +/* Number of bits in a byte. */ +#ifndef NBBY +# ifdef __NBBY +# define NBBY __NBBY +# else +# define NBBY 8 +# endif +#endif + +/* Bit map macros. */ +#define sudo_setbit(_a, _i) ((_a)[(_i) / NBBY] |= 1 << ((_i) % NBBY)) +#define sudo_clrbit(_a, _i) ((_a)[(_i) / NBBY] &= ~(1<<((_i) % NBBY))) +#define sudo_isset(_a, _i) ((_a)[(_i) / NBBY] & (1<<((_i) % NBBY))) +#define sudo_isclr(_a, _i) (((_a)[(_i) / NBBY] & (1<<((_i) % NBBY))) == 0) + /* * List of debug files and flags for use in registration. */ @@ -227,11 +242,11 @@ __dso_public void sudo_debug_exit_str(const char *func, const char *file, int li __dso_public void sudo_debug_exit_str_masked(const char *func, const char *file, int line, int subsys, const char *rval); __dso_public pid_t sudo_debug_fork(void); __dso_public int sudo_debug_get_default_instance(void); -__dso_public int sudo_debug_get_fds(fd_set **fdsetp); +__dso_public int sudo_debug_get_fds(unsigned char **fds); __dso_public int sudo_debug_get_instance(const char *program); __dso_public void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printf0like(5, 6); __dso_public void sudo_debug_printf_nvm(int pri, const char *fmt, ...) __printf0like(2, 3); -__dso_public int sudo_debug_register(const char *program, const char *const subsystems[], int ids[], struct sudo_conf_debug_file_list *debug_files); +__dso_public int sudo_debug_register(const char *program, const char *const subsystems[], unsigned int ids[], struct sudo_conf_debug_file_list *debug_files); __dso_public int sudo_debug_set_default_instance(int inst); __dso_public void sudo_debug_update_fd(int ofd, int nfd); __dso_public void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0); diff --git a/lib/util/Makefile.in b/lib/util/Makefile.in index c30172ac3..5fc2b8870 100644 --- a/lib/util/Makefile.in +++ b/lib/util/Makefile.in @@ -74,7 +74,7 @@ SSP_LDFLAGS = @SSP_LDFLAGS@ SHLIB_VERSION = 0:0:0 # cppcheck options, usually set in the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64 # Regression tests TEST_PROGS = atofoo_test conf_test hltq_test parseln_test progname_test @COMPAT_TEST_PROGS@ diff --git a/lib/util/sudo_debug.c b/lib/util/sudo_debug.c index 264745a29..6b5ecb44b 100644 --- a/lib/util/sudo_debug.c +++ b/lib/util/sudo_debug.c @@ -16,13 +16,6 @@ #include -#include /* for howmany() on Linux */ -#ifdef HAVE_SYS_SYSMACROS_H -# include /* for howmany() on Solaris */ -#endif -#ifdef HAVE_SYS_SELECT_H -# include -#endif /* HAVE_SYS_SELECT_H */ #include #include #include @@ -119,7 +112,7 @@ SLIST_HEAD(sudo_debug_output_list, sudo_debug_output); struct sudo_debug_instance { char *program; const char *const *subsystems; - const int *subsystem_ids; + const unsigned int *subsystem_ids; unsigned int max_subsystem; struct sudo_debug_output_list outputs; }; @@ -132,7 +125,8 @@ static int sudo_debug_last_instance = -1; static char sudo_debug_pidstr[(((sizeof(int) * 8) + 2) / 3) + 3]; static size_t sudo_debug_pidlen; -static fd_set sudo_debug_fdset; /* XXX - make dynamic */ +static const int sudo_debug_fdset_size = 1024 * NBBY; /* XXX - make dynamic */ +static unsigned char sudo_debug_fds[1024]; /* XXX - make dynamic */ static int sudo_debug_max_fd = -1; /* Default instance index to use for common utility functions. */ @@ -173,9 +167,9 @@ sudo_debug_new_output(struct sudo_debug_instance *instance, ignore_result(fchown(output->fd, (uid_t)-1, 0)); } (void)fcntl(output->fd, F_SETFD, FD_CLOEXEC); - /* XXX - realloc sudo_debug_fdset as needed (or use other bitmap). */ - if (output->fd < FD_SETSIZE) { - FD_SET(output->fd, &sudo_debug_fdset); + /* XXX - realloc sudo_debug_fds as needed. */ + if (output->fd < sudo_debug_fdset_size) { + sudo_setbit(sudo_debug_fds, output->fd); if (output->fd > sudo_debug_max_fd) sudo_debug_max_fd = output->fd; } @@ -197,13 +191,13 @@ sudo_debug_new_output(struct sudo_debug_instance *instance, if (strcasecmp(pri, sudo_debug_priorities[i]) == 0) { for (j = 0; instance->subsystems[j] != NULL; j++) { if (strcasecmp(subsys, "all") == 0) { - const int idx = instance->subsystem_ids ? + const unsigned int idx = instance->subsystem_ids ? SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]) : j; output->settings[idx] = i; continue; } if (strcasecmp(subsys, instance->subsystems[j]) == 0) { - const int idx = instance->subsystem_ids ? + const unsigned int idx = instance->subsystem_ids ? SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]) : j; output->settings[idx] = i; break; @@ -227,7 +221,7 @@ sudo_debug_new_output(struct sudo_debug_instance *instance, */ int sudo_debug_register(const char *program, const char *const subsystems[], - int ids[], struct sudo_conf_debug_file_list *debug_files) + unsigned int ids[], struct sudo_conf_debug_file_list *debug_files) { struct sudo_debug_instance *instance = NULL; struct sudo_debug_output *output; @@ -809,17 +803,17 @@ sudo_debug_set_default_instance(int inst) /* * Replace the ofd with nfd in all outputs if present. - * Also updates sudo_debug_fdset. + * Also updates sudo_debug_fds. */ void sudo_debug_update_fd(int ofd, int nfd) { int idx; - if (ofd <= sudo_debug_max_fd && FD_ISSET(ofd, &sudo_debug_fdset)) { - /* Update sudo_debug_fdset. */ - FD_CLR(ofd, &sudo_debug_fdset); - FD_SET(nfd, &sudo_debug_fdset); + if (ofd <= sudo_debug_max_fd && sudo_isset(sudo_debug_fds, ofd)) { + /* Update sudo_debug_fds. */ + sudo_clrbit(sudo_debug_fds, ofd); + sudo_setbit(sudo_debug_fds, nfd); /* Update the outputs. */ for (idx = 0; idx <= sudo_debug_last_instance; idx++) { @@ -839,11 +833,11 @@ sudo_debug_update_fd(int ofd, int nfd) /* * Returns the highest debug output fd or -1 if no debug files open. - * Fills in fdsetp with the value of sudo_debug_fdset. + * Fills in fdsetp with the value of sudo_debug_fds. */ int -sudo_debug_get_fds(fd_set **fdsetp) +sudo_debug_get_fds(unsigned char **fds) { - *fdsetp = &sudo_debug_fdset; + *fds = sudo_debug_fds; return sudo_debug_max_fd; } diff --git a/plugins/group_file/Makefile.in b/plugins/group_file/Makefile.in index 38c41bc85..4fb4ed6ab 100644 --- a/plugins/group_file/Makefile.in +++ b/plugins/group_file/Makefile.in @@ -58,7 +58,7 @@ SSP_CFLAGS = @SSP_CFLAGS@ SSP_LDFLAGS = @SSP_LDFLAGS@ # cppcheck options, usually set in the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64 # Where to install things... prefix = @prefix@ diff --git a/plugins/sample/Makefile.in b/plugins/sample/Makefile.in index cff2910eb..80a2656b9 100644 --- a/plugins/sample/Makefile.in +++ b/plugins/sample/Makefile.in @@ -57,7 +57,7 @@ SSP_CFLAGS = @SSP_CFLAGS@ SSP_LDFLAGS = @SSP_LDFLAGS@ # cppcheck options, usually set in the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64 # Where to install things... prefix = @prefix@ diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index af026a198..8d6ba530b 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -76,7 +76,7 @@ SSP_CFLAGS = @SSP_CFLAGS@ SSP_LDFLAGS = @SSP_LDFLAGS@ # cppcheck options, usually set in the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64 # Where to install things... prefix = @prefix@ diff --git a/plugins/sudoers/sudoers_debug.c b/plugins/sudoers/sudoers_debug.c index eecc1ae13..6ad3f611a 100644 --- a/plugins/sudoers/sudoers_debug.c +++ b/plugins/sudoers/sudoers_debug.c @@ -71,7 +71,7 @@ static const char *const sudoers_subsystem_names[] = { #define NUM_SUBSYSTEMS (sizeof(sudoers_subsystem_names) / sizeof(sudoers_subsystem_names[0]) - 1) /* Subsystem IDs assigned at registration time. */ -int sudoers_subsystem_ids[NUM_SUBSYSTEMS]; +unsigned int sudoers_subsystem_ids[NUM_SUBSYSTEMS]; /* * Parse the "filename flags,..." debug_flags entry and insert a new diff --git a/plugins/sudoers/sudoers_debug.h b/plugins/sudoers/sudoers_debug.h index c7e4fd779..4c3ac5bc7 100644 --- a/plugins/sudoers/sudoers_debug.h +++ b/plugins/sudoers/sudoers_debug.h @@ -23,7 +23,7 @@ * Sudoers debug subsystems. * Note that sudoers_subsystem_ids[] is filled in at debug registration time. */ -extern int sudoers_subsystem_ids[]; +extern unsigned int sudoers_subsystem_ids[]; #define SUDOERS_DEBUG_ALIAS (sudoers_subsystem_ids[ 0]) /* sudoers alias functions */ #define SUDOERS_DEBUG_AUDIT (sudoers_subsystem_ids[ 1]) /* audit */ #define SUDOERS_DEBUG_AUTH (sudoers_subsystem_ids[ 2]) /* authentication functions */ diff --git a/plugins/system_group/Makefile.in b/plugins/system_group/Makefile.in index 18023e2b6..be5721ac4 100644 --- a/plugins/system_group/Makefile.in +++ b/plugins/system_group/Makefile.in @@ -58,7 +58,7 @@ SSP_CFLAGS = @SSP_CFLAGS@ SSP_LDFLAGS = @SSP_LDFLAGS@ # cppcheck options, usually set in the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64 # Where to install things... prefix = @prefix@ diff --git a/src/Makefile.in b/src/Makefile.in index f01a0a2cb..ba93ca927 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -58,7 +58,7 @@ SSP_CFLAGS = @SSP_CFLAGS@ SSP_LDFLAGS = @SSP_LDFLAGS@ # cppcheck options, usually set in the top-level Makefile -CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64 +CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64 # Where to install things... prefix = @prefix@ diff --git a/src/exec.c b/src/exec.c index 128c7f88f..2b53f3d06 100644 --- a/src/exec.c +++ b/src/exec.c @@ -174,12 +174,12 @@ exec_cmnd(struct command_details *details, struct command_status *cstat, details->argv, details->envp); if (details->closefrom >= 0) { int fd, maxfd; - fd_set *debug_fds; + unsigned char *debug_fds; /* Preserve debug fds and error pipe as needed. */ maxfd = sudo_debug_get_fds(&debug_fds); for (fd = 0; fd <= maxfd; fd++) { - if (FD_ISSET(fd, debug_fds)) + if (sudo_isset(debug_fds, fd)) add_preserved_fd(&details->preserved_fds, fd); } if (errfd != -1)