From 88d3a31c17d1d60c8701ee4ed21c6ec566e80f6b Mon Sep 17 00:00:00 2001 From: "Roland C. Dowdeswell" Date: Wed, 18 Jan 2012 14:41:07 +0000 Subject: [PATCH] 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. --- lib/roken/getxxyyy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/roken/getxxyyy.c b/lib/roken/getxxyyy.c index 267dec140..b97dd8e63 100644 --- a/lib/roken/getxxyyy.c +++ b/lib/roken/getxxyyy.c @@ -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");