Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/from Use appropriate errx/err at the right places.



details:   https://anonhg.NetBSD.org/src/rev/92264139a697
branches:  trunk
changeset: 511956:92264139a697
user:      mjl <mjl%NetBSD.org@localhost>
date:      Sun Jul 01 00:09:46 2001 +0000

description:
Use appropriate errx/err at the right places.
Use snprintf() when dealing with user supplied arg.

diffstat:

 usr.bin/from/from.c |  19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diffs (57 lines):

diff -r 933bfa223e45 -r 92264139a697 usr.bin/from/from.c
--- a/usr.bin/from/from.c       Sat Jun 30 22:35:05 2001 +0000
+++ b/usr.bin/from/from.c       Sun Jul 01 00:09:46 2001 +0000
@@ -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 @@
 #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 <sys/types.h>
@@ -83,7 +83,6 @@
                                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 @@
                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') {



Home | Main Index | Thread Index | Old Index