Skip to content

Commit

Permalink
Merge sudo 1.9.16p2 from tip.
Browse files Browse the repository at this point in the history
--HG--
branch : 1.9
  • Loading branch information
millert committed Nov 25, 2024
2 parents 1fbc146 + 73cbe4e commit 172cbd9
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 65 deletions.
15 changes: 15 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
What's new in Sudo 1.9.16p2

* Sudo now passes the terminal device number to the policy plugin
even if it cannot resolve it to a path name. This allows sudo
to run without warnings in a chroot jail when the terminal device
files are not present. GitHub issue #421.

* On Linux systems, sudo will now attempt to use the symbolic links
in /proc/self/fd/{0,1,2} when resolving the terminal device
number. This can allow sudo to map a terminal device to its
path name even when /dev/pts is not mounted in a chroot jail.

* Fixed compilation errors with gcc and clang in C23 mode.
C23 no longer supports functions with unspecified arguments.

What's new in Sudo 1.9.16p1

* Fixed the test for cross-compiling when checking for C99 snprintf().
Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.72 for sudo 1.9.16p1.
# Generated by GNU Autoconf 2.72 for sudo 1.9.16p2.
#
# Report bugs to <https://bugzilla.sudo.ws/>.
#
Expand Down Expand Up @@ -614,8 +614,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='sudo'
PACKAGE_TARNAME='sudo'
PACKAGE_VERSION='1.9.16p1'
PACKAGE_STRING='sudo 1.9.16p1'
PACKAGE_VERSION='1.9.16p2'
PACKAGE_STRING='sudo 1.9.16p2'
PACKAGE_BUGREPORT='https://bugzilla.sudo.ws/'
PACKAGE_URL=''

Expand Down Expand Up @@ -1645,7 +1645,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
'configure' configures sudo 1.9.16p1 to adapt to many kinds of systems.
'configure' configures sudo 1.9.16p2 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

Expand Down Expand Up @@ -1711,7 +1711,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of sudo 1.9.16p1:";;
short | recursive ) echo "Configuration of sudo 1.9.16p2:";;
esac
cat <<\_ACEOF

Expand Down Expand Up @@ -2006,7 +2006,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
sudo configure 1.9.16p1
sudo configure 1.9.16p2
generated by GNU Autoconf 2.72

Copyright (C) 2023 Free Software Foundation, Inc.
Expand Down Expand Up @@ -2826,7 +2826,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by sudo $as_me 1.9.16p1, which was
It was created by sudo $as_me 1.9.16p2, which was
generated by GNU Autoconf 2.72. Invocation command line was

$ $0$ac_configure_args_raw
Expand Down Expand Up @@ -36774,7 +36774,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by sudo $as_me 1.9.16p1, which was
This file was extended by sudo $as_me 1.9.16p2, which was
generated by GNU Autoconf 2.72. Invocation command line was

CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -36842,7 +36842,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
sudo config.status 1.9.16p1
sudo config.status 1.9.16p2
configured by $0, generated by GNU Autoconf 2.72,
with options \\"\$ac_cs_config\\"

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
dnl OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
dnl
AC_PREREQ([2.69])
AC_INIT([sudo], [1.9.16p1], [https://bugzilla.sudo.ws/], [sudo])
AC_INIT([sudo], [1.9.16p2], [https://bugzilla.sudo.ws/], [sudo])
AC_CONFIG_HEADERS([config.h pathnames.h])
AC_CONFIG_SRCDIR([src/sudo.c])
AC_CONFIG_AUX_DIR([scripts])
Expand Down
4 changes: 4 additions & 0 deletions include/sudo_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ typedef int (*sudo_printf_t)(int msg_type, const char * restrict fmt, ...);
#endif

/* Hook functions typedefs. */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
typedef int (*sudo_hook_fn_t)(...);
#else
typedef int (*sudo_hook_fn_t)();
#endif
typedef int (*sudo_hook_fn_setenv_t)(const char *name, const char *value, int overwrite, void *closure);
typedef int (*sudo_hook_fn_putenv_t)(char *string, void *closure);
typedef int (*sudo_hook_fn_getenv_t)(const char *name, char **value, void *closure);
Expand Down
2 changes: 1 addition & 1 deletion lib/util/regress/parse_gids/parse_gids_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static struct parse_gids_test test_data[] = {
{ "1,2,3,4", &test_data[0].basegid, 0, 5, test1_out },
{ "1,2,3,4", NULL, 0, 4, test2_out },
{ "1,-2,3,4", &test_data[2].basegid, 0, 5, test3_out },
{ NULL, false, 0, 0, NULL }
{ NULL, NULL, 0, 0, NULL }
};

static void
Expand Down
2 changes: 1 addition & 1 deletion lib/util/setgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sudo_setgroups_v1(int ngids, const GETGROUPS_T *gids)
if (maxgids == -1)
maxgids = NGROUPS_MAX;
if (ngids > maxgids)
ret = setgroups(maxgids, (GETGROUPS_T *)gids);
ret = setgroups((int)maxgids, (GETGROUPS_T *)gids);
}
debug_return_int(ret);
}
30 changes: 29 additions & 1 deletion lib/util/ttyname_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,39 @@ char *
sudo_ttyname_dev_v1(dev_t rdev, char *buf, size_t buflen)
{
const char *devsearch, *devsearch_end;
char path[PATH_MAX], *ret;
char path[PATH_MAX], *ret = NULL;
const char *cp, *ep;
size_t len;
debug_decl(sudo_ttyname_dev, SUDO_DEBUG_UTIL);

#ifdef __linux__
/*
* First check std{in,out,err} and use /proc/self/fd/{0,1,2} if possible.
*/
for (int fd = STDIN_FILENO; fd <= STDERR_FILENO; fd++) {
char fdpath[] = "/proc/self/fd/N";
struct stat sb;

if (fstat(fd, &sb) == -1 || !S_ISCHR(sb.st_mode))
continue;
if (rdev != sb.st_rdev)
continue;

fdpath[sizeof("/proc/self/fd/N") - 2] = '0' + fd;
len = readlink(fdpath, buf, buflen);
if (len != (size_t)-1) {
if (len == buflen) {
errno = ERANGE; /* buf too small */
} else {
/* readlink(2) does not NUL-terminate. */
buf[len] = '\0';
ret = buf;
}
goto done;
}
}
#endif

/*
* First, check /dev/console.
*/
Expand Down
2 changes: 1 addition & 1 deletion plugins/sudoers/cvtsudoers_ldif.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ print_global_defaults_ldif(FILE *fp,
lbuf.len = 0;
if (!sudo_lbuf_append(&lbuf, "# "))
goto done;
if (!sudoers_format_default_line(&lbuf, parse_tree, opt, false, true))
if (!sudoers_format_default_line(&lbuf, parse_tree, opt, NULL, true))
goto done;
fprintf(fp, "# Unable to translate %s:%d:%d:\n%s\n",
opt->file, opt->line, opt->column, lbuf.buf);
Expand Down
10 changes: 6 additions & 4 deletions plugins/sudoers/cvtsudoers_pwutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1)
struct cache_item_grlist *grlitem;
struct sudoers_string *s;
struct group_list *grlist;
size_t groupname_len;
long groupname_len;
debug_decl(cvtsudoers_make_grlist_item, SUDOERS_DEBUG_NSS);

/*
Expand All @@ -421,15 +421,17 @@ cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1)
}

#ifdef _SC_LOGIN_NAME_MAX
groupname_len = (size_t)MAX(sysconf(_SC_LOGIN_NAME_MAX), 32);
groupname_len = sysconf(_SC_LOGIN_NAME_MAX);
if (groupname_len < 32)
groupname_len = 32;
#else
groupname_len = MAX(LOGIN_NAME_MAX, 32);
#endif

/* Allocate in one big chunk for easy freeing. */
nsize = strlen(pw->pw_name) + 1;
total = sizeof(*grlitem) + nsize;
total += groupname_len * ngroups;
total += (size_t)groupname_len * ngroups;

again:
if ((grlitem = calloc(1, total)) == NULL) {
Expand Down Expand Up @@ -470,7 +472,7 @@ cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1)
}
len = strlen(s->str) + 1;
if ((size_t)(cp - (char *)grlitem) + len > total) {
total += len + groupname_len;
total += len + (size_t)groupname_len;
free(grlitem);
goto again;
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/sudoers/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,10 +1358,10 @@ sudoers_policy_version(int verbose)
}

static struct sudo_hook sudoers_hooks[] = {
{ SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, sudoers_hook_setenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, sudoers_hook_unsetenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, sudoers_hook_getenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, sudoers_hook_putenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, (sudo_hook_fn_t)sudoers_hook_setenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, (sudo_hook_fn_t)sudoers_hook_unsetenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, (sudo_hook_fn_t)sudoers_hook_getenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, (sudo_hook_fn_t)sudoers_hook_putenv, NULL },
{ 0, 0, NULL, NULL }
};

Expand Down
13 changes: 8 additions & 5 deletions plugins/sudoers/pwutil_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,13 @@ PREFIX(make_gidlist_item)(const struct passwd *pw, int ngids, GETGROUPS_T *gids,
struct cache_item *
PREFIX(make_grlist_item)(const struct passwd *pw, char * const *unused1)
{
char *cp;
size_t groupname_len, len, ngroups, nsize, total;
size_t len, ngroups, nsize, total;
struct cache_item_grlist *grlitem;
struct group_list *grlist;
struct gid_list *gidlist;
struct group *grp = NULL;
long groupname_len;
char *cp;
int i;
debug_decl(sudo_make_grlist_item, SUDOERS_DEBUG_NSS);

Expand All @@ -381,7 +382,9 @@ PREFIX(make_grlist_item)(const struct passwd *pw, char * const *unused1)
}

#ifdef _SC_LOGIN_NAME_MAX
groupname_len = (size_t)MAX(sysconf(_SC_LOGIN_NAME_MAX), 32);
groupname_len = sysconf(_SC_LOGIN_NAME_MAX);
if (groupname_len < 32)
groupname_len = 32;
#else
groupname_len = MAX(LOGIN_NAME_MAX, 32);
#endif
Expand All @@ -390,7 +393,7 @@ PREFIX(make_grlist_item)(const struct passwd *pw, char * const *unused1)
nsize = strlen(pw->pw_name) + 1;
total = sizeof(*grlitem) + nsize;
total += sizeof(char *) * (size_t)gidlist->ngids;
total += groupname_len * (size_t)gidlist->ngids;
total += (size_t)(groupname_len * gidlist->ngids);

again:
if ((grlitem = calloc(1, total)) == NULL) {
Expand Down Expand Up @@ -429,7 +432,7 @@ PREFIX(make_grlist_item)(const struct passwd *pw, char * const *unused1)
if ((grp = sudo_getgrgid(gidlist->gids[i])) != NULL) {
len = strlen(grp->gr_name) + 1;
if ((size_t)(cp - (char *)grlitem) + len > total) {
total += len + groupname_len;
total += len + (size_t)groupname_len;
free(grlitem);
sudo_gr_delref(grp);
goto again;
Expand Down
2 changes: 1 addition & 1 deletion plugins/sudoers/sudo_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sudo_printf_int(int msg_type, const char * restrict fmt, ...)
va_end(ap);
}
if (len != -1) {
if (fwrite(buf, 1, len, ttyfp ? ttyfp : fp) == 0)
if (fwrite(buf, 1, (size_t)len, ttyfp ? ttyfp : fp) == 0)
len = -1;
if (buf != sbuf)
free(buf);
Expand Down
4 changes: 2 additions & 2 deletions plugins/sudoers/sudoreplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,9 +1678,9 @@ read_keyboard(int fd, int what, void *v)
static void
display_usage(FILE *fp)
{
fprintf(fp, _("usage: %s [-hnRS] [-d dir] [-m num] [-s num] ID\n"),
fprintf(fp, "usage: %s [-hnRS] [-d dir] [-m num] [-s num] ID\n",
getprogname());
fprintf(fp, _("usage: %s [-h] [-d dir] -l [search expression]\n"),
fprintf(fp, "usage: %s [-h] [-d dir] -l [search expression]\n",
getprogname());
}

Expand Down
2 changes: 1 addition & 1 deletion src/conversation.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ sudo_conversation_printf(int msg_type, const char * restrict fmt, ...)
va_end(ap);
}
if (len != -1) {
if (fwrite(buf, 1, len, ttyfp ? ttyfp : fp) == 0)
if (fwrite(buf, 1, (size_t)len, ttyfp ? ttyfp : fp) == 0)
len = -1;
if (buf != sbuf)
free(buf);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ process_hooks_unsetenv(const char *name)
/* Hook registration internals. */
static int
register_hook_internal(struct sudo_hook_list *head,
int (*hook_fn)(), void *closure)
sudo_hook_fn_t hook_fn, void *closure)
{
struct sudo_hook_entry *hook;
debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS);
Expand Down Expand Up @@ -185,7 +185,7 @@ register_hook(struct sudo_hook *hook)
/* Hook deregistration internals. */
static void
deregister_hook_internal(struct sudo_hook_list *head,
int (*hook_fn)(), void *closure)
sudo_hook_fn_t hook_fn, void *closure)
{
struct sudo_hook_entry *hook, *prev = NULL;
debug_decl(deregister_hook_internal, SUDO_DEBUG_HOOKS);
Expand Down
11 changes: 7 additions & 4 deletions src/sudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,13 @@ get_user_info(struct user_details *ud)
if (ttydev != (dev_t)-1) {
if (asprintf(&info[++i], "ttydev=%lld", (long long)ttydev) == -1)
goto oom;
info[++i] = sudo_new_key_val("tty", path);
if (info[i] == NULL)
goto oom;
ud->tty = info[i] + sizeof("tty=") - 1;
/* The terminal device file may be missing in a chroot() jail. */
if (path[0] != '\0') {
info[++i] = sudo_new_key_val("tty", path);
if (info[i] == NULL)
goto oom;
ud->tty = info[i] + sizeof("tty=") - 1;
}
} else {
/* tty may not always be present */
if (errno != ENOENT)
Expand Down
Loading

0 comments on commit 172cbd9

Please sign in to comment.