summaryrefslogtreecommitdiff
path: root/usr.bin/msgs
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-08-02 04:10:51 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-08-02 04:10:51 +0000
commiteb9184a174a8fb2f98f2f1418f87863716a5c115 (patch)
tree02b606fefe2b41782be054be7fdd586e53befba0 /usr.bin/msgs
parent3602a750205b32f442e2e132baa5b3e9a3c83349 (diff)
$HOME paranoia: never use getenv("HOME") w/o checking for NULL and non-zero
Diffstat (limited to 'usr.bin/msgs')
-rw-r--r--usr.bin/msgs/msgs.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/msgs/msgs.c b/usr.bin/msgs/msgs.c
index e17be79f5ca..54e2d940f37 100644
--- a/usr.bin/msgs/msgs.c
+++ b/usr.bin/msgs/msgs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: msgs.c,v 1.16 2000/07/06 06:24:39 deraadt Exp $ */
+/* $OpenBSD: msgs.c,v 1.17 2000/08/02 04:10:48 millert Exp $ */
/* $NetBSD: msgs.c,v 1.7 1995/09/28 06:57:40 tls Exp $ */
/*-
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)msgs.c 8.2 (Berkeley) 4/28/95";
#else
-static char rcsid[] = "$OpenBSD: msgs.c,v 1.16 2000/07/06 06:24:39 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: msgs.c,v 1.17 2000/08/02 04:10:48 millert Exp $";
#endif
#endif /* not lint */
@@ -172,6 +172,7 @@ main(argc, argv)
int firstmsg, nextmsg, lastmsg = 0;
int blast = 0;
FILE *bounds;
+ char *cp;
#ifdef UNBUFFERED
setbuf(stdout, NULL);
@@ -294,9 +295,9 @@ main(argc, argv)
lastmsg = 0;
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)){
- register char *cp = dp->d_name;
register int i = 0;
+ cp = dp->d_name;
if (dp->d_ino == 0)
continue;
if (dp->d_namlen == 0)
@@ -417,7 +418,11 @@ main(argc, 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;