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
This commit is contained in:
Michael Vetter 2019-11-11 13:10:51 +01:00
parent 59c2dabb26
commit 88fa0651bf

View 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);