Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/banner Correct handling of empty arguments as report...



details:   https://anonhg.NetBSD.org/src/rev/3907a4b41fd9
branches:  trunk
changeset: 544155:3907a4b41fd9
user:      mjl <mjl%NetBSD.org@localhost>
date:      Thu Mar 13 11:57:23 2003 +0000

description:
Correct handling of empty arguments as reported in OpenBSD PR/3146.
While there use strlcpy instead of strncpy and STDOUT_FILENO instead of 1.

diffstat:

 usr.bin/banner/banner.c |  13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diffs (48 lines):

diff -r db25038eb41b -r 3907a4b41fd9 usr.bin/banner/banner.c
--- a/usr.bin/banner/banner.c   Thu Mar 13 11:35:54 2003 +0000
+++ b/usr.bin/banner/banner.c   Thu Mar 13 11:57:23 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: banner.c,v 1.7 2001/02/20 23:51:59 cgd Exp $   */
+/*     $NetBSD: banner.c,v 1.8 2003/03/13 11:57:23 mjl Exp $   */
 
 /*
  *     Changes for banner(1)
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: banner.c,v 1.7 2001/02/20 23:51:59 cgd Exp $");
+__RCSID("$NetBSD: banner.c,v 1.8 2003/03/13 11:57:23 mjl Exp $");
 #endif
 #endif /* not lint */
 
@@ -141,7 +141,7 @@
                if (BackGnd != ' ')
                    *strp++ = BackGnd;
                sp = scsp;
-               for (nchrs = 0; ; ) {
+               for (nchrs = 0; *sp != dlm && *sp != '\0'; ) {
                        d = dropit(c = TRC(cc = *sp++));
                        if ((!d && scnhgt > HEIGHT) || (scnhgt <= Drop && d))
                                for (j = WIDTH; --j;)
@@ -152,7 +152,7 @@
                        else
                                strp = scnline(
                                    scnkey_lpd[(int)c][scnhgt-1-d], strp, cc);
-                       if (*sp == dlm || *sp == '\0' || nchrs++ >= PW/(WIDTH+1)-1)
+                       if (nchrs++ >= PW/(WIDTH+1)-1)
                                break;
                        *strp++ = BackGnd;
                }
@@ -197,9 +197,8 @@
        }
 
        for (; optind < argc; ++optind) {
-               (void)strncpy(word, argv[optind], sizeof (word) - 1);
-               word[sizeof (word) - 1] = '\0';
-               scan_out(1, word, '\0');
+               (void)strlcpy(word, argv[optind], sizeof (word));
+               scan_out(STDOUT_FILENO, word, '\0');
        }
        exit(0);
 }



Home | Main Index | Thread Index | Old Index