Never use getenv("HOME") without checking for NULL and non-zero
Obtained from: OpenBSD
This commit is contained in:
parent
fa99a6317c
commit
0f10497bce
@ -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 &&
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user