From d268644440170ea52e124061e2d848278c693c90 Mon Sep 17 00:00:00 2001 From: guoxiaoqi Date: Mon, 16 Dec 2019 10:31:44 -0500 Subject: [PATCH] fix invalid path Signed-off-by: guoxiaoqi --- src/useradd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/useradd.c b/src/useradd.c index cafbe90..930b4ea 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -1276,6 +1276,21 @@ static void process_flags (int argc, char **argv) exit (E_BAD_ARG); } user_shell = optarg; + struct stat st; + if (stat (optarg, &st) != 0) { + if ((ENOENT == errno) || (ENOTDIR == errno)) { + /* The file or directory does not exist */ + fprintf (stderr, + _("%s: warning :The file %s is not exist\n"), + Prog, optarg); + exit (E_BAD_ARG); + } + } else if ((st.st_mode & S_IXUSR) == 0) { + fprintf (stderr, + _("%s: warning :The file %s is not executable\n"), + Prog, optarg); + exit (E_BAD_ARG); + } def_shell = optarg; sflg = true; break; -- 1.8.3.1