From 5f98a040ccf16947e992c8c923d983edc454472d Mon Sep 17 00:00:00 2001 From: mjl Date: Sun, 1 Jul 2001 00:09:46 +0000 Subject: [PATCH] Use appropriate errx/err at the right places. Use snprintf() when dealing with user supplied arg. --- usr.bin/from/from.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/usr.bin/from/from.c b/usr.bin/from/from.c index 160434b07ac9..b35fe73e9b28 100644 --- a/usr.bin/from/from.c +++ b/usr.bin/from/from.c @@ -1,4 +1,4 @@ -/* $NetBSD: from.c,v 1.12 2000/09/08 13:14:33 mjl Exp $ */ +/* $NetBSD: from.c,v 1.13 2001/07/01 00:09:46 mjl Exp $ */ /* * Copyright (c) 1980, 1988, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1988, 1993\n\ #if 0 static char sccsid[] = "@(#)from.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: from.c,v 1.12 2000/09/08 13:14:33 mjl Exp $"); +__RCSID("$NetBSD: from.c,v 1.13 2001/07/01 00:09:46 mjl Exp $"); #endif /* not lint */ #include @@ -83,7 +83,6 @@ main(int argc, char **argv) if (isupper((unsigned char)*p)) *p = tolower(*p); break; - case '?': default: fprintf(stderr, "usage: from [-f file] [-s sender] [user]\n"); exit(1); @@ -101,22 +100,24 @@ main(int argc, char **argv) if (!(file = *argv)) { if (!(file = getenv("MAIL"))) { if (!(pwd = getpwuid(getuid()))) - err(1, "no password file entry for you"); + errx(1, "no password file entry for you"); if ((file = getenv("USER")) != NULL) { - (void)sprintf(buf, "%s/%s", - _PATH_MAILDIR, file); + (void)snprintf(buf, sizeof(buf), + "%s/%s", _PATH_MAILDIR, file); file = buf; } else - (void)sprintf(file = buf, "%s/%s", + (void)snprintf(file = buf, sizeof(buf), + "%s/%s", _PATH_MAILDIR, pwd->pw_name); } } else { - (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, file); + (void)snprintf(buf, sizeof(buf), "%s/%s", + _PATH_MAILDIR, file); file = buf; } } if (!freopen(file, "r", stdin)) - errx(1, "can't read %s", file); + err(1, "can't read %s", file); for (newline = 1; fgets(buf, sizeof(buf), stdin);) { if (*buf == '\n') {