From: Todd C. Miller Date: Thu, 5 Feb 2015 18:17:25 +0000 (-0700) Subject: Don't assume argv[0] is set without first checking argc. X-Git-Tag: SUDO_1_8_12^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67eba7e53469792f3f9416d62ed505b1bfae33d5;p=sudo Don't assume argv[0] is set without first checking argc. --- diff --git a/src/parse_args.c b/src/parse_args.c index 3f7e5ccc1..0681c5b48 100644 --- a/src/parse_args.c +++ b/src/parse_args.c @@ -379,8 +379,10 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, } env_add[nenv] = NULL; - argc -= optind; - argv += optind; + if (argc > 0) { + argc -= optind; + argv += optind; + } if (!mode) { /* Defer -k mode setting until we know whether it is a flag or not */ diff --git a/src/sudo.c b/src/sudo.c index 77858af2a..438a10ab0 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -183,7 +183,7 @@ main(int argc, char *argv[], char *envp[]) NULL, NULL, sudo_conf_debug_files(getprogname())); /* Make sure we are setuid root. */ - sudo_check_suid(argv[0]); + sudo_check_suid(argc > 0 ? argv[0] : "sudo"); /* Reset signal mask, save signal state and make sure fds 0-2 are open. */ (void) sigemptyset(&mask);