aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKevin Lo <kevlo@FreeBSD.org>2007-10-30 03:44:10 +0000
committerKevin Lo <kevlo@FreeBSD.org>2007-10-30 03:44:10 +0000
commit0f10497bce8fb709cfc14f9f898c32fef81d4089 (patch)
tree8a90af60acc60174122b0a69e0a47ec744ea809a /usr.bin
parentfa99a6317c6d78a03a0ccd7dd183f58b564eb14d (diff)
downloadsrc-0f10497bce8fb709cfc14f9f898c32fef81d4089.tar.gz
src-0f10497bce8fb709cfc14f9f898c32fef81d4089.zip
Never use getenv("HOME") without checking for NULL and non-zero
Obtained from: OpenBSD
Notes
Notes: svn path=/head/; revision=173169
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/calendar/io.c5
-rw-r--r--usr.bin/msgs/msgs.c9
2 files changed, 11 insertions, 3 deletions
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index e5a0a086e393..49bfa5329986 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 &&
diff --git a/usr.bin/msgs/msgs.c b/usr.bin/msgs/msgs.c
index 23f224047b1f..2172735aec17 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;