src/rc/supervise-daemon.c: do not pass NULL to strcmp

The following will cause a segfault due to NULL being
passed to strcmp(3)

$ RC_SVCNAME=foo supervise-daemon

Fix the bounds check on argc in main. If argc<=1, then
it is not safe to dereference argv[1].
This commit is contained in:
philhofer 2018-12-23 12:42:33 -08:00 committed by Mike Frysinger
parent 40f7046696
commit a9fc26ac13

View File

@ -720,7 +720,7 @@ int main(int argc, char **argv)
eerrorx("%s: The RC_SVCNAME environment variable is not set", applet); eerrorx("%s: The RC_SVCNAME environment variable is not set", applet);
openlog(applet, LOG_PID, LOG_DAEMON); openlog(applet, LOG_PID, LOG_DAEMON);
if (argc >= 1 && svcname && strcmp(argv[1], svcname)) if (argc <= 1 || strcmp(argv[1], svcname))
eerrorx("%s: the first argument is %s and must be %s", eerrorx("%s: the first argument is %s and must be %s",
applet, argv[1], svcname); applet, argv[1], svcname);