librc: fix rc_runlevel_exists return for empty string

This function should return false if the runlevel is an empty string.

    X-Gentoo-Bug: 803536
    X-Gentoo-Bug-URL: https://bugs.gentoo.org/803536
    Closes: https://github.com/OpenRC/openrc/pull/431
This commit is contained in:
William Hubbs 2021-08-13 10:28:44 -05:00
parent dec9ef200b
commit 0a97bad6c9

View File

@ -481,7 +481,8 @@ rc_runlevel_exists(const char *runlevel)
char path[PATH_MAX];
struct stat buf;
if (!runlevel || strcmp(runlevel, ".") == 0 || strcmp(runlevel, "..") == 0)
if (!runlevel || strcmp(runlevel, "") == 0 || strcmp(runlevel, ".") == 0 ||
strcmp(runlevel, "..") == 0)
return false;
snprintf(path, sizeof(path), "%s/%s", RC_RUNLEVELDIR, runlevel);
if (stat(path, &buf) == 0 && S_ISDIR(buf.st_mode))