make check fails if USER environment variable unset.
getxxyyy.c uses the USER environment variable to determine a user to test getpwnam_r(). If this variable is unset then the test will seg fault. We work around this issue by defaulting to ``root'' if USER is not set. This is not perfect as root may not exist on the system but given that user does exist on most systems, this is the best default that we can choose if we have no other options available.
This commit is contained in:
@@ -111,13 +111,18 @@ main(int argc, char **argv)
|
||||
struct passwd pwd, *result;
|
||||
char buf[1024];
|
||||
int ret;
|
||||
const char *user;
|
||||
|
||||
ret = rk_getpwnam_r(getenv("USER"), &pwd, buf, sizeof(buf), &result);
|
||||
user = getenv("USER");
|
||||
if (!user)
|
||||
user = "root";
|
||||
|
||||
ret = rk_getpwnam_r(user, &pwd, buf, sizeof(buf), &result);
|
||||
if (ret)
|
||||
errx(1, "rk_getpwnam_r");
|
||||
print_result(result);
|
||||
|
||||
ret = rk_getpwnam_r(getenv("USER"), &pwd, buf, 1, &result);
|
||||
ret = rk_getpwnam_r(user, &pwd, buf, 1, &result);
|
||||
if (ret == 0)
|
||||
errx(1, "rk_getpwnam_r too small buf");
|
||||
|
||||
|
Reference in New Issue
Block a user