]> sourceware.org Git - glibc.git/commitdiff
Use read_int in vfscanf
authorGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Tue, 20 Sep 2016 17:19:27 +0000 (14:19 -0300)
committerGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Wed, 26 Oct 2016 11:56:24 +0000 (09:56 -0200)
The function read_int, from printf-parse.h, parses an integer from a string
while avoiding overflows.  It is used by other functions, such as vfprintf,
to avoid undefined behavior.

The function vfscanf (_IO_vfwscanf) parses an integer from the format
string, and can use read_int.

ChangeLog
stdio-common/vfscanf.c

index de9056e92a9e7d28d4c422cb9e7e3e93a5eb8ea8..4b91b6ab7045aef5b7ea8dd8346773f3f8cea99a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-26  Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>
+
+       * stdio-common/vfscanf.c (_IO_vfwscanf): Use read_int to parse
+       integer from the format string.
+
 2016-10-26  Florian Weimer  <fweimer@redhat.com>
 
        [BZ #19473]
index fe3677ba102e1f9057e1608b17dcc7a648e5c1df..7caa96fbe2c947dded18b0508fe3ddb3f5d58c82 100644 (file)
 # define WINT_T                int
 #endif
 
+#include "printf-parse.h" /* Use read_int.  */
+
 #define encode_error() do {                                                  \
                          errval = 4;                                         \
                          __set_errno (EILSEQ);                               \
@@ -488,9 +490,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
       /* Check for a positional parameter specification.  */
       if (ISDIGIT ((UCHAR_T) *f))
        {
-         argpos = (UCHAR_T) *f++ - L_('0');
-         while (ISDIGIT ((UCHAR_T) *f))
-           argpos = argpos * 10 + ((UCHAR_T) *f++ - L_('0'));
+         argpos = read_int ((const UCHAR_T **) &f);
          if (*f == L_('$'))
            ++f;
          else
@@ -525,11 +525,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
 
       /* Find the maximum field width.  */
       width = 0;
-      while (ISDIGIT ((UCHAR_T) *f))
-       {
-         width *= 10;
-         width += (UCHAR_T) *f++ - L_('0');
-       }
+      if (ISDIGIT ((UCHAR_T) *f))
+       width = read_int ((const UCHAR_T **) &f);
     got_width:
       if (width == 0)
        width = -1;
This page took 0.14468 seconds and 5 git commands to generate.