From 9a9592dceb6f0e4272fe29a22e426edd9092ae74 Mon Sep 17 00:00:00 2001 From: kevlo Date: Tue, 30 Oct 2007 03:44:10 +0000 Subject: Never use getenv("HOME") without checking for NULL and non-zero Obtained from: OpenBSD --- usr.bin/calendar/io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'usr.bin/calendar') diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index e5a0a08..49bfa53 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -337,7 +337,10 @@ opencal(void) if (!freopen(calendarFile, "r", stdin)) return (NULL); } else { - chdir(getenv("HOME")); + char *home = getenv("HOME"); + if (home == NULL || *home == '\0') + errx(1, "cannot get home directory"); + chdir(home); for (found = i = 0; i < sizeof(calendarHomes) / sizeof(calendarHomes[0]); i++) if (chdir(calendarHomes[i]) == 0 && -- cgit v1.1