summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 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 &&
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;
OpenPOWER on IntegriCloud