]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: check for valid shell argument 187/head
authorMichael Vetter <jubalh@iodoru.org>
Mon, 11 Nov 2019 12:10:51 +0000 (13:10 +0100)
committerMichael Vetter <jubalh@iodoru.org>
Mon, 11 Nov 2019 12:46:25 +0000 (13:46 +0100)
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

index e074844d000da258e25f3de3cd06c3d7dc103648..16af77f2ea157e209a47bb958a690482352164ee 100644 (file)
@@ -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);