From 88fa0651bfa4be0c819da0027456f5046a3b4967 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 11 Nov 2019 13:10:51 +0100 Subject: [PATCH] useradd: check for valid shell argument Check whether shell argument given with `-s` is actually present and executable. And is not a directory. Fix https://github.com/shadow-maint/shadow/issues/186 --- src/useradd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/useradd.c b/src/useradd.c index e074844d..16af77f2 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -1094,6 +1094,7 @@ static void process_flags (int argc, char **argv) const struct group *grp; bool anyflag = false; char *cp; + struct stat st; { /* @@ -1310,7 +1311,10 @@ static void process_flags (int argc, char **argv) if ( ( !VALID (optarg) ) || ( ('\0' != optarg[0]) && ('/' != optarg[0]) - && ('*' != optarg[0]) )) { + && ('*' != optarg[0]) ) + || (stat(optarg, &st) != 0) + || (S_ISDIR(st.st_mode)) + || (access(optarg, X_OK != 0))) { fprintf (stderr, _("%s: invalid shell '%s'\n"), Prog, optarg);