Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/printf Avoid segv on "printf '%*********s' 666", fro...



details:   https://anonhg.NetBSD.org/src/rev/826145a9aa2f
branches:  trunk
changeset: 748100:826145a9aa2f
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Oct 13 19:28:31 2009 +0000

description:
Avoid segv on "printf '%*********s' 666", from Maksymilian Arciemowicz

diffstat:

 usr.bin/printf/printf.c |  24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diffs (55 lines):

diff -r 2ad51d372f97 -r 826145a9aa2f usr.bin/printf/printf.c
--- a/usr.bin/printf/printf.c   Tue Oct 13 18:41:06 2009 +0000
+++ b/usr.bin/printf/printf.c   Tue Oct 13 19:28:31 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printf.c,v 1.33 2008/07/21 14:19:24 lukem Exp $        */
+/*     $NetBSD: printf.c,v 1.34 2009/10/13 19:28:31 christos Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)printf.c   8.2 (Berkeley) 3/22/95";
 #else
-__RCSID("$NetBSD: printf.c,v 1.33 2008/07/21 14:19:24 lukem Exp $");
+__RCSID("$NetBSD: printf.c,v 1.34 2009/10/13 19:28:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -155,7 +155,7 @@
        gargv = ++argv;
 
 #define SKIP1  "#-+ 0"
-#define SKIP2  "*0123456789"
+#define SKIP2  "0123456789"
        do {
                /*
                 * Basic algorithm is to scan the format string for conversion
@@ -185,13 +185,23 @@
 
                        /* skip to field width */
                        fmt += strspn(fmt, SKIP1);
-                       fieldwidth = *fmt == '*' ? getwidth() : -1;
+                       if (*fmt == '*') {
+                               fmt++;
+                               fieldwidth = getwidth();
+                       } else
+                               fieldwidth = -1;
 
                        /* skip to possible '.', get following precision */
                        fmt += strspn(fmt, SKIP2);
-                       if (*fmt == '.')
-                               ++fmt;
-                       precision = *fmt == '*' ? getwidth() : -1;
+                       if (*fmt == '.') {
+                               fmt++;
+                               if (*fmt == '*') {
+                                       fmt++;
+                                       precision = getwidth();
+                               } else
+                                       precision = -1;
+                       } else
+                               precision = -1;
 
                        fmt += strspn(fmt, SKIP2);
 



Home | Main Index | Thread Index | Old Index