9d1b3f
diff -up ./config.h.in.CVE-2019-19234 ./config.h.in
9d1b3f
--- ./config.h.in.CVE-2019-19234	2019-10-28 13:28:52.000000000 +0100
9d1b3f
+++ ./config.h.in	2020-01-14 15:53:40.506988064 +0100
9d1b3f
@@ -334,6 +334,9 @@
9d1b3f
 /* Define to 1 if you have the `getuserattr' function. */
9d1b3f
 #undef HAVE_GETUSERATTR
9d1b3f
 
9d1b3f
+/* Define to 1 if you have the `getusershell' function. */
9d1b3f
+#undef HAVE_GETUSERSHELL
9d1b3f
+
9d1b3f
 /* Define to 1 if you have the `getutid' function. */
9d1b3f
 #undef HAVE_GETUTID
9d1b3f
 
9d1b3f
diff -up ./configure.ac.CVE-2019-19234 ./configure.ac
9d1b3f
--- ./configure.ac.CVE-2019-19234	2020-01-14 15:53:40.496987995 +0100
9d1b3f
+++ ./configure.ac	2020-01-14 15:53:40.509988084 +0100
9d1b3f
@@ -2562,6 +2562,10 @@ AC_CHECK_FUNCS([getdelim], [], [
9d1b3f
     SUDO_APPEND_COMPAT_EXP(sudo_getdelim)
9d1b3f
     COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }getdelim_test"
9d1b3f
 ])
9d1b3f
+AC_CHECK_FUNCS([getusershell], [], [
9d1b3f
+    AC_LIBOBJ(getusershell)
9d1b3f
+    SUDO_APPEND_COMPAT_EXP(sudo_getusershell)
9d1b3f
+])
9d1b3f
 AC_CHECK_FUNCS([reallocarray], [], [
9d1b3f
     AC_LIBOBJ(reallocarray)
9d1b3f
     SUDO_APPEND_COMPAT_EXP(sudo_reallocarray)
9d1b3f
diff -up ./configure.CVE-2019-19234 ./configure
9d1b3f
--- ./configure.CVE-2019-19234	2019-10-28 13:29:14.000000000 +0100
9d1b3f
+++ ./configure	2020-01-14 15:53:40.509988084 +0100
9d1b3f
@@ -19395,6 +19395,32 @@ esac
9d1b3f
 fi
9d1b3f
 done
9d1b3f
 
9d1b3f
+for ac_func in getusershell
9d1b3f
+do :
9d1b3f
+  ac_fn_c_check_func "$LINENO" "getusershell" "ac_cv_func_getusershell"
9d1b3f
+if test "x$ac_cv_func_getusershell" = xyes; then :
9d1b3f
+  cat >>confdefs.h <<_ACEOF
9d1b3f
+#define HAVE_GETUSERSHELL 1
9d1b3f
+_ACEOF
9d1b3f
+
9d1b3f
+else
9d1b3f
+
9d1b3f
+    case " $LIBOBJS " in
9d1b3f
+  *" getusershell.$ac_objext "* ) ;;
9d1b3f
+  *) LIBOBJS="$LIBOBJS getusershell.$ac_objext"
9d1b3f
+ ;;
9d1b3f
+esac
9d1b3f
+
9d1b3f
+
9d1b3f
+    for _sym in sudo_getusershell; do
9d1b3f
+	COMPAT_EXP="${COMPAT_EXP}${_sym}
9d1b3f
+"
9d1b3f
+    done
9d1b3f
+
9d1b3f
+
9d1b3f
+fi
9d1b3f
+done
9d1b3f
+
9d1b3f
 for ac_func in reallocarray
9d1b3f
 do :
9d1b3f
   ac_fn_c_check_func "$LINENO" "reallocarray" "ac_cv_func_reallocarray"
9d1b3f
diff -up ./doc/sudoers.man.in.CVE-2019-19234 ./doc/sudoers.man.in
9d1b3f
--- ./doc/sudoers.man.in.CVE-2019-19234	2020-01-14 15:53:40.503988043 +0100
9d1b3f
+++ ./doc/sudoers.man.in	2020-01-14 15:53:40.510988091 +0100
9d1b3f
@@ -2959,6 +2959,28 @@ Older versions of
9d1b3f
 \fBsudo\fR
9d1b3f
 always allowed matching of unknown user and group IDs.
9d1b3f
 .TP 18n
9d1b3f
+runas_check_shell
9d1b3f
+.br
9d1b3f
+If enabled,
9d1b3f
+\fBsudo\fR
9d1b3f
+will only run commands as a user whose shell appears in the
9d1b3f
+\fI/etc/shells\fR
9d1b3f
+file, even if the invoking user's
9d1b3f
+\fRRunas_List\fR
9d1b3f
+would otherwise permit it.
9d1b3f
+If no
9d1b3f
+\fI/etc/shells\fR
9d1b3f
+file is present, a system-dependent list of built-in default shells is used.
9d1b3f
+On many operating systems, system users such as
9d1b3f
+\(lqbin\(rq,
9d1b3f
+do not have a valid shell and this flag can be used to prevent
9d1b3f
+commands from being run as those users.
9d1b3f
+This flag is
9d1b3f
+\fIoff\fR
9d1b3f
+by default.
9d1b3f
+.sp
9d1b3f
+This setting is only supported by version 1.8.29 or higher.
9d1b3f
+.TP 18n
9d1b3f
 runaspw
9d1b3f
 If set,
9d1b3f
 \fBsudo\fR
9d1b3f
diff -up ./doc/sudoers.mdoc.in.CVE-2019-19234 ./doc/sudoers.mdoc.in
9d1b3f
--- ./doc/sudoers.mdoc.in.CVE-2019-19234	2020-01-14 15:53:40.504988050 +0100
9d1b3f
+++ ./doc/sudoers.mdoc.in	2020-01-14 15:53:40.510988091 +0100
9d1b3f
@@ -2784,6 +2784,26 @@ This setting is only supported by versio
9d1b3f
 Older versions of
9d1b3f
 .Nm sudo
9d1b3f
 always allowed matching of unknown user and group IDs.
9d1b3f
+.It runas_check_shell
9d1b3f
+If enabled,
9d1b3f
+.Nm sudo
9d1b3f
+will only run commands as a user whose shell appears in the
9d1b3f
+.Pa /etc/shells
9d1b3f
+file, even if the invoking user's
9d1b3f
+.Li Runas_List
9d1b3f
+would otherwise permit it.
9d1b3f
+If no
9d1b3f
+.Pa /etc/shells
9d1b3f
+file is present, a system-dependent list of built-in default shells is used.
9d1b3f
+On many operating systems, system users such as
9d1b3f
+.Dq bin ,
9d1b3f
+do not have a valid shell and this flag can be used to prevent
9d1b3f
+commands from being run as those users.
9d1b3f
+This flag is
9d1b3f
+.Em off
9d1b3f
+by default.
9d1b3f
+.Pp
9d1b3f
+This setting is only supported by version 1.8.29 or higher.
9d1b3f
 .It runaspw
9d1b3f
 If set,
9d1b3f
 .Nm sudo
9d1b3f
diff -up ./include/sudo_compat.h.CVE-2019-19234 ./include/sudo_compat.h
9d1b3f
--- ./include/sudo_compat.h.CVE-2019-19234	2019-10-28 13:28:52.000000000 +0100
9d1b3f
+++ ./include/sudo_compat.h	2020-01-14 15:53:40.511988098 +0100
9d1b3f
@@ -407,6 +407,17 @@ __dso_public ssize_t sudo_getdelim(char
9d1b3f
 # undef getdelim
9d1b3f
 # define getdelim(_a, _b, _c, _d) sudo_getdelim((_a), (_b), (_c), (_d))
9d1b3f
 #endif /* HAVE_GETDELIM */
9d1b3f
+#ifndef HAVE_GETUSERSHELL
9d1b3f
+__dso_public char *sudo_getusershell(void);
9d1b3f
+# undef getusershell
9d1b3f
+# define getusershell() sudo_getusershell()
9d1b3f
+__dso_public void sudo_setusershell(void);
9d1b3f
+# undef setusershell
9d1b3f
+# define setusershell() sudo_setusershell()
9d1b3f
+__dso_public void sudo_endusershell(void);
9d1b3f
+# undef endusershell
9d1b3f
+# define endusershell() sudo_endusershell()
9d1b3f
+#endif /* HAVE_GETUSERSHELL */
9d1b3f
 #ifndef HAVE_UTIMENSAT
9d1b3f
 __dso_public int sudo_utimensat(int fd, const char *file, const struct timespec *times, int flag);
9d1b3f
 # undef utimensat
9d1b3f
diff -up ./lib/util/getusershell.c.CVE-2019-19234 ./lib/util/getusershell.c
9d1b3f
--- ./lib/util/getusershell.c.CVE-2019-19234	2020-01-14 15:53:40.511988098 +0100
9d1b3f
+++ ./lib/util/getusershell.c	2020-01-14 15:53:40.511988098 +0100
9d1b3f
@@ -0,0 +1,138 @@
9d1b3f
+/*
9d1b3f
+ * SPDX-License-Identifier: ISC
9d1b3f
+ *
9d1b3f
+ * Copyright (c) 2019 Todd C. Miller <Todd.Miller@courtesan.com>
9d1b3f
+ *
9d1b3f
+ * Permission to use, copy, modify, and distribute this software for any
9d1b3f
+ * purpose with or without fee is hereby granted, provided that the above
9d1b3f
+ * copyright notice and this permission notice appear in all copies.
9d1b3f
+ *
9d1b3f
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9d1b3f
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9d1b3f
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9d1b3f
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
9d1b3f
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
9d1b3f
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
9d1b3f
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
9d1b3f
+ */
9d1b3f
+
9d1b3f
+/*
9d1b3f
+ * This is an open source non-commercial project. Dear PVS-Studio, please check it.
9d1b3f
+ * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9d1b3f
+ */
9d1b3f
+
9d1b3f
+#include <config.h>
9d1b3f
+
9d1b3f
+#include <sys/types.h>
9d1b3f
+
9d1b3f
+#include <stdio.h>
9d1b3f
+#include <stdlib.h>
9d1b3f
+#include <string.h>
9d1b3f
+#include <ctype.h>
9d1b3f
+#include <errno.h>
9d1b3f
+
9d1b3f
+#define DEFAULT_TEXT_DOMAIN     "sudo"
9d1b3f
+#include "sudo_gettext.h"       /* must be included before sudo_compat.h */
9d1b3f
+
9d1b3f
+#include "sudo_compat.h"
9d1b3f
+#include "sudo_debug.h"
9d1b3f
+#include "sudo_util.h"
9d1b3f
+
9d1b3f
+static char **allowed_shells, **current_shell;
9d1b3f
+static char *default_shells[] = {
9d1b3f
+    "/bin/sh",
9d1b3f
+    "/bin/ksh",
9d1b3f
+    "/bin/ksh93",
9d1b3f
+    "/bin/bash",
9d1b3f
+    "/bin/dash",
9d1b3f
+    "/bin/zsh",
9d1b3f
+    "/bin/csh",
9d1b3f
+    "/bin/tcsh",
9d1b3f
+    NULL
9d1b3f
+};
9d1b3f
+
9d1b3f
+static char **
9d1b3f
+read_shells(void)
9d1b3f
+{
9d1b3f
+    size_t maxshells = 16, nshells = 0;
9d1b3f
+    size_t linesize = 0;
9d1b3f
+    char *line = NULL;
9d1b3f
+    FILE *fp;
9d1b3f
+    debug_decl(read_shells, SUDO_DEBUG_UTIL)
9d1b3f
+
9d1b3f
+    if ((fp = fopen("/etc/shells", "r")) == NULL)
9d1b3f
+	goto bad;
9d1b3f
+
9d1b3f
+    free(allowed_shells);
9d1b3f
+    allowed_shells = reallocarray(NULL, maxshells, sizeof(char *));
9d1b3f
+    if (allowed_shells == NULL)
9d1b3f
+	goto bad;
9d1b3f
+
9d1b3f
+    while (sudo_parseln(&line, &linesize, NULL, fp, PARSELN_CONT_IGN) != -1) {
9d1b3f
+	if (nshells + 1 >= maxshells) {
9d1b3f
+	    char **new_shells;
9d1b3f
+
9d1b3f
+	    new_shells = reallocarray(NULL, maxshells + 16, sizeof(char *));
9d1b3f
+	    if (new_shells == NULL)
9d1b3f
+		goto bad;
9d1b3f
+	    allowed_shells = new_shells;
9d1b3f
+	    maxshells += 16;
9d1b3f
+	}
9d1b3f
+	if ((allowed_shells[nshells] = strdup(line)) == NULL)
9d1b3f
+	    goto bad;
9d1b3f
+	nshells++;
9d1b3f
+    }
9d1b3f
+    allowed_shells[nshells] = NULL;
9d1b3f
+
9d1b3f
+    free(line);
9d1b3f
+    fclose(fp);
9d1b3f
+    debug_return_ptr(allowed_shells);
9d1b3f
+bad:
9d1b3f
+    free(line);
9d1b3f
+    if (fp != NULL)
9d1b3f
+	fclose(fp);
9d1b3f
+    while (nshells != 0)
9d1b3f
+	free(allowed_shells[--nshells]);
9d1b3f
+    free(allowed_shells);
9d1b3f
+    allowed_shells = NULL;
9d1b3f
+    debug_return_ptr(default_shells);
9d1b3f
+}
9d1b3f
+
9d1b3f
+void
9d1b3f
+sudo_setusershell(void)
9d1b3f
+{
9d1b3f
+    debug_decl(setusershell, SUDO_DEBUG_UTIL)
9d1b3f
+
9d1b3f
+    current_shell = read_shells();
9d1b3f
+
9d1b3f
+    debug_return;
9d1b3f
+}
9d1b3f
+
9d1b3f
+void
9d1b3f
+sudo_endusershell(void)
9d1b3f
+{
9d1b3f
+    debug_decl(endusershell, SUDO_DEBUG_UTIL)
9d1b3f
+
9d1b3f
+    if (allowed_shells != NULL) {
9d1b3f
+	char **shell;
9d1b3f
+
9d1b3f
+	for (shell = allowed_shells; *shell != NULL; shell++)
9d1b3f
+	    free(*shell);
9d1b3f
+	free(allowed_shells);
9d1b3f
+	allowed_shells = NULL;
9d1b3f
+    }
9d1b3f
+    current_shell = NULL;
9d1b3f
+
9d1b3f
+    debug_return;
9d1b3f
+}
9d1b3f
+
9d1b3f
+char *
9d1b3f
+sudo_getusershell(void)
9d1b3f
+{
9d1b3f
+    debug_decl(getusershell, SUDO_DEBUG_UTIL)
9d1b3f
+
9d1b3f
+    if (current_shell == NULL)
9d1b3f
+	current_shell = read_shells();
9d1b3f
+
9d1b3f
+    debug_return_str(*current_shell++);
9d1b3f
+}
9d1b3f
diff -up ./lib/util/Makefile.in.CVE-2019-19234 ./lib/util/Makefile.in
9d1b3f
--- ./lib/util/Makefile.in.CVE-2019-19234	2019-10-28 13:28:53.000000000 +0100
9d1b3f
+++ ./lib/util/Makefile.in	2020-01-14 15:53:40.511988098 +0100
9d1b3f
@@ -678,6 +678,18 @@ gettime.i: $(srcdir)/gettime.c $(incdir)
9d1b3f
 	$(CC) -E -o $@ $(CPPFLAGS) $<
9d1b3f
 gettime.plog: gettime.i
9d1b3f
 	rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/gettime.c --i-file $< --output-file $@
9d1b3f
+getusershell.lo: $(srcdir)/getusershell.c $(incdir)/compat/stdbool.h \
9d1b3f
+                 $(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
9d1b3f
+                 $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
9d1b3f
+                 $(incdir)/sudo_util.h $(top_builddir)/config.h
9d1b3f
+	$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/getusershell.c
9d1b3f
+getusershell.i: $(srcdir)/getusershell.c $(incdir)/compat/stdbool.h \
9d1b3f
+                 $(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
9d1b3f
+                 $(incdir)/sudo_gettext.h $(incdir)/sudo_queue.h \
9d1b3f
+                 $(incdir)/sudo_util.h $(top_builddir)/config.h
9d1b3f
+	$(CC) -E -o $@ $(CPPFLAGS) $<
9d1b3f
+getusershell.plog: getusershell.i
9d1b3f
+	rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/getusershell.c --i-file $< --output-file $@
9d1b3f
 gidlist.lo: $(srcdir)/gidlist.c $(incdir)/compat/stdbool.h \
9d1b3f
             $(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
9d1b3f
             $(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
9d1b3f
diff -up ./MANIFEST.CVE-2019-19234 ./MANIFEST
9d1b3f
--- ./MANIFEST.CVE-2019-19234	2019-10-28 13:28:52.000000000 +0100
9d1b3f
+++ ./MANIFEST	2020-01-14 15:53:40.506988064 +0100
9d1b3f
@@ -103,6 +103,7 @@ lib/util/getgrouplist.c
9d1b3f
 lib/util/gethostname.c
9d1b3f
 lib/util/getopt_long.c
9d1b3f
 lib/util/gettime.c
9d1b3f
+lib/util/getusershell.c
9d1b3f
 lib/util/gidlist.c
9d1b3f
 lib/util/glob.c
9d1b3f
 lib/util/inet_ntop.c
9d1b3f
diff -up ./mkdep.pl.CVE-2019-19234 ./mkdep.pl
9d1b3f
--- ./mkdep.pl.CVE-2019-19234	2019-10-28 13:28:52.000000000 +0100
9d1b3f
+++ ./mkdep.pl	2020-01-14 15:53:40.511988098 +0100
9d1b3f
@@ -116,7 +116,7 @@ sub mkdep {
9d1b3f
     # XXX - fill in AUTH_OBJS from contents of the auth dir instead
9d1b3f
     $makefile =~ s:\@AUTH_OBJS\@:afs.lo aix_auth.lo bsdauth.lo dce.lo fwtk.lo getspwuid.lo kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid5.lo sia.lo:;
9d1b3f
     $makefile =~ s:\@DIGEST\@:digest.lo digest_openssl.lo digest_gcrypt.lo:;
9d1b3f
-    $makefile =~ s:\@LTLIBOBJS\@:arc4random.lo arc4random_uniform.lo closefrom.lo fnmatch.lo getaddrinfo.lo getcwd.lo getentropy.lo getgrouplist.lo getdelim.lo getopt_long.lo glob.lo inet_ntop_lo inet_pton.lo isblank.lo memrchr.lo memset_s.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo pw_dup.lo reallocarray.lo sha2.lo sig2str.lo siglist.lo signame.lo snprintf.lo str2sig.lo strlcat.lo strlcpy.lo strndup.lo strnlen.lo strsignal.lo utimens.lo vsyslog.lo pipe2.lo:;
9d1b3f
+    $makefile =~ s:\@LTLIBOBJS\@:arc4random.lo arc4random_uniform.lo closefrom.lo fnmatch.lo getaddrinfo.lo getcwd.lo getentropy.lo getgrouplist.lo getdelim.lo getopt_long.lo getusershell.lo glob.lo inet_ntop_lo inet_pton.lo isblank.lo memrchr.lo memset_s.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo pw_dup.lo reallocarray.lo sha2.lo sig2str.lo siglist.lo signame.lo snprintf.lo str2sig.lo strlcat.lo strlcpy.lo strndup.lo strnlen.lo strsignal.lo utimens.lo vsyslog.lo pipe2.lo:;
9d1b3f
 
9d1b3f
     # Parse OBJS lines
9d1b3f
     my %objs;
9d1b3f
diff -up ./plugins/sudoers/check.c.CVE-2019-19234 ./plugins/sudoers/check.c
9d1b3f
--- ./plugins/sudoers/check.c.CVE-2019-19234	2019-10-28 13:27:45.000000000 +0100
9d1b3f
+++ ./plugins/sudoers/check.c	2020-01-14 15:53:40.511988098 +0100
9d1b3f
@@ -333,3 +333,28 @@ get_authpw(int mode)
9d1b3f
 
9d1b3f
     debug_return_ptr(pw);
9d1b3f
 }
9d1b3f
+
9d1b3f
+/*
9d1b3f
+ * Returns true if the specified shell is allowed by /etc/shells, else false.
9d1b3f
+ */
9d1b3f
+bool
9d1b3f
+check_user_shell(const struct passwd *pw)
9d1b3f
+{
9d1b3f
+    const char *shell;
9d1b3f
+    debug_decl(check_user_shell, SUDOERS_DEBUG_AUTH)
9d1b3f
+
9d1b3f
+    if (!def_runas_check_shell)
9d1b3f
+	debug_return_bool(true);
9d1b3f
+
9d1b3f
+    sudo_debug_printf(SUDO_DEBUG_INFO,
9d1b3f
+	"%s: checking /etc/shells for %s", __func__, pw->pw_shell);
9d1b3f
+
9d1b3f
+    setusershell();
9d1b3f
+    while ((shell = getusershell()) != NULL) {
9d1b3f
+	if (strcmp(shell, pw->pw_shell) == 0)
9d1b3f
+	    debug_return_bool(true);
9d1b3f
+    }
9d1b3f
+    endusershell();
9d1b3f
+
9d1b3f
+    debug_return_bool(false);
9d1b3f
+}
9d1b3f
diff -up ./plugins/sudoers/def_data.c.CVE-2019-19234 ./plugins/sudoers/def_data.c
9d1b3f
--- ./plugins/sudoers/def_data.c.CVE-2019-19234	2020-01-14 15:53:40.504988050 +0100
9d1b3f
+++ ./plugins/sudoers/def_data.c	2020-01-14 15:53:40.511988098 +0100
9d1b3f
@@ -518,6 +518,10 @@ struct sudo_defs_types sudo_defs_table[]
9d1b3f
 	N_("Allow the use of unknown runas user and/or group ID"),
9d1b3f
 	NULL,
9d1b3f
     }, {
9d1b3f
+	"runas_check_shell", T_FLAG,
9d1b3f
+	N_("Only permit running commands as a user with a valid shell"),
9d1b3f
+	NULL,
9d1b3f
+    }, {
9d1b3f
 	NULL, 0, NULL
9d1b3f
     }
9d1b3f
 };
9d1b3f
diff -up ./plugins/sudoers/def_data.h.CVE-2019-19234 ./plugins/sudoers/def_data.h
9d1b3f
--- ./plugins/sudoers/def_data.h.CVE-2019-19234	2020-01-14 15:53:40.512988105 +0100
9d1b3f
+++ ./plugins/sudoers/def_data.h	2020-01-14 15:58:06.927808982 +0100
9d1b3f
@@ -238,6 +238,8 @@
9d1b3f
 #define def_cmnd_no_wait        (sudo_defs_table[I_CMND_NO_WAIT].sd_un.flag)
9d1b3f
 #define I_RUNAS_ALLOW_UNKNOWN_ID 119
9d1b3f
 #define def_runas_allow_unknown_id (sudo_defs_table[I_RUNAS_ALLOW_UNKNOWN_ID].sd_un.flag)
9d1b3f
+#define I_RUNAS_CHECK_SHELL     120
9d1b3f
+#define def_runas_check_shell   (sudo_defs_table[I_RUNAS_CHECK_SHELL].sd_un.flag)
9d1b3f
 
9d1b3f
 enum def_tuple {
9d1b3f
 	never,
9d1b3f
diff -up ./plugins/sudoers/def_data.in.CVE-2019-19234 ./plugins/sudoers/def_data.in
9d1b3f
--- ./plugins/sudoers/def_data.in.CVE-2019-19234	2020-01-14 15:53:40.505988057 +0100
9d1b3f
+++ ./plugins/sudoers/def_data.in	2020-01-14 15:53:40.512988105 +0100
9d1b3f
@@ -375,3 +375,7 @@ cmnd_no_wait
9d1b3f
 runas_allow_unknown_id
9d1b3f
 	T_FLAG
9d1b3f
 	"Allow the use of unknown runas user and/or group ID"
9d1b3f
+runas_check_shell
9d1b3f
+	T_FLAG
9d1b3f
+	"Only permit running commands as a user with a valid shell"
9d1b3f
+
9d1b3f
diff -up ./plugins/sudoers/sudoers.c.CVE-2019-19234 ./plugins/sudoers/sudoers.c
9d1b3f
--- ./plugins/sudoers/sudoers.c.CVE-2019-19234	2020-01-14 15:53:40.505988057 +0100
9d1b3f
+++ ./plugins/sudoers/sudoers.c	2020-01-14 15:53:40.512988105 +0100
9d1b3f
@@ -273,7 +273,7 @@ sudoers_policy_main(int argc, char * con
9d1b3f
 	/* Not an audit event. */
9d1b3f
 	sudo_warnx(U_("sudoers specifies that root is not allowed to sudo"));
9d1b3f
 	goto bad;
9d1b3f
-    }    
9d1b3f
+    }
9d1b3f
 
9d1b3f
     if (!set_perms(PERM_INITIAL))
9d1b3f
 	goto bad;
9d1b3f
@@ -412,6 +412,13 @@ sudoers_policy_main(int argc, char * con
9d1b3f
 	goto bad;
9d1b3f
     }
9d1b3f
 
9d1b3f
+    /* Check runas user's shell. */
9d1b3f
+    if (!check_user_shell(runas_pw)) {
9d1b3f
+	log_warningx(SLOG_RAW_MSG, N_("invalid shell for user %s: %s"),
9d1b3f
+	    runas_pw->pw_name, runas_pw->pw_shell);
9d1b3f
+	goto bad;
9d1b3f
+    }
9d1b3f
+
9d1b3f
     /*
9d1b3f
      * We don't reset the environment for sudoedit or if the user
9d1b3f
      * specified the -E command line flag and they have setenv privs.
9d1b3f
diff -up ./plugins/sudoers/sudoers.h.CVE-2019-19234 ./plugins/sudoers/sudoers.h
9d1b3f
--- ./plugins/sudoers/sudoers.h.CVE-2019-19234	2020-01-14 15:53:40.502988036 +0100
9d1b3f
+++ ./plugins/sudoers/sudoers.h	2020-01-14 15:53:40.512988105 +0100
9d1b3f
@@ -264,6 +264,7 @@ int find_path(const char *infile, char *
9d1b3f
 
9d1b3f
 /* check.c */
9d1b3f
 int check_user(int validate, int mode);
9d1b3f
+bool check_user_shell(const struct passwd *pw);
9d1b3f
 bool user_is_exempt(void);
9d1b3f
 
9d1b3f
 /* prompt.c */