diff options
author | kevlo <kevlo@FreeBSD.org> | 2007-10-30 03:44:10 +0000 |
---|---|---|
committer | kevlo <kevlo@FreeBSD.org> | 2007-10-30 03:44:10 +0000 |
commit | 9a9592dceb6f0e4272fe29a22e426edd9092ae74 (patch) | |
tree | 8a90af60acc60174122b0a69e0a47ec744ea809a /usr.bin/msgs | |
parent | b5d104ba4d2fd20589d18b21e13ef7b90328ab70 (diff) | |
download | FreeBSD-src-9a9592dceb6f0e4272fe29a22e426edd9092ae74.zip FreeBSD-src-9a9592dceb6f0e4272fe29a22e426edd9092ae74.tar.gz |
Never use getenv("HOME") without checking for NULL and non-zero
Obtained from: OpenBSD
Diffstat (limited to 'usr.bin/msgs')
-rw-r--r-- | usr.bin/msgs/msgs.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.bin/msgs/msgs.c b/usr.bin/msgs/msgs.c index 23f2240..2172735 100644 --- a/usr.bin/msgs/msgs.c +++ b/usr.bin/msgs/msgs.c @@ -171,6 +171,7 @@ main(int argc, char *argv[]) int blast = 0; struct stat buf; /* stat to check access of bounds */ FILE *bounds; + char *cp; #ifdef UNBUFFERED setbuf(stdout, NULL); @@ -286,7 +287,7 @@ main(int argc, char *argv[]) lastmsg = 0; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)){ - char *cp = dp->d_name; + cp = dp->d_name; int i = 0; if (dp->d_ino == 0) @@ -402,7 +403,11 @@ main(int argc, char *argv[]) totty = (isatty(fileno(stdout)) != 0); use_pager = use_pager && totty; - snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), MSGSRC); + if ((cp = getenv("HOME")) == NULL || *cp == '\0') { + fprintf(stderr, "Error, no home directory!\n"); + exit(1); + } + snprintf(fname, sizeof(fname), "%s/%s", cp, MSGSRC); msgsrc = fopen(fname, "r"); if (msgsrc) { newrc = NO; |