If fork fails in System(), don't fallthrough to exec()

In the unlikely event of a failure in creating processes, signal
masks will fall from the panels above you.  Secure your mask before
telling your child what to do, since it won't exist, and you will
instead cause the server itself to be replaced by a shell running
the target program.

Found by Coverity #53397: Missing break in switch
Execution falls through to the next case statement or default;
 this might indicate a common typo.
In System: Missing break statement between cases in switch statement (CWE-484)

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Alan Coopersmith 2014-10-09 05:42:09 -07:00 committed by Keith Packard
parent 7e5bc49d1e
commit 16a32c53f6
1 changed files with 1 additions and 0 deletions

View File

@ -1373,6 +1373,7 @@ System(const char *command)
switch (pid = fork()) {
case -1: /* error */
p = -1;
break;
case 0: /* child */
if (setgid(getgid()) == -1)
_exit(127);