Ticket #13949: 0001-strtod-Do-not-consume-x-in-incomplete-hex-input.patch

File 0001-strtod-Do-not-consume-x-in-incomplete-hex-input.patch, 2.3 KB (added by i80and, 7 years ago)
  • src/system/libroot/posix/glibc/stdlib/strtod.c

    From 129059eed514f5e6076277b688b86ed88d9a4b15 Mon Sep 17 00:00:00 2001
    From: Andrew Aldridge <i80and@foxquill.com>
    Date: Thu, 11 Jan 2018 21:22:52 +0000
    Subject: [PATCH] strtod: Do not consume "x" in incomplete hex input
    
    Adapted from upstream glibc commits:
    * 405698e946dbed472491f85867eb511eb080e05a
    * 43b9d657408fbf47a47934f9e7c84ed87f7f5a18
    
    Fixes #13949
    ---
     src/system/libroot/posix/glibc/stdlib/strtod.c | 29 ++++++++++++++++++--------
     1 file changed, 20 insertions(+), 9 deletions(-)
    
    diff --git a/src/system/libroot/posix/glibc/stdlib/strtod.c b/src/system/libroot/posix/glibc/stdlib/strtod.c
    index 85642b89cf..b5d82692ab 100644
    a b INTERNAL (STRTOF) (nptr, endptr, group LOCALE_PARAM)  
    674674
    675675  /* If no other digit but a '0' is found the result is 0.0.
    676676     Return current read pointer.  */
    677   if ((c < L_('0') || c > L_('9'))
    678       && (base == 16 && (c < TOLOWER (L_('a')) || c > TOLOWER (L_('f'))))
     677  if (!((c >= L_('0') && c <= L_('9'))
     678    || (base == 16 && ((CHAR_TYPE) TOLOWER (c) >= L_('a')
     679               && (CHAR_TYPE) TOLOWER (c) <= L_('f')))
     680    || (
    679681#ifdef USE_WIDE_CHAR
    680       && c != decimal
     682        c == (wint_t) decimal
    681683#else
    682       && ({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
    683           if (decimal[cnt] != cp[cnt])
    684         break;
    685         decimal[cnt] != '\0'; })
     684        ({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
     685        if (decimal[cnt] != cp[cnt])
     686           break;
     687           decimal[cnt] == '\0'; })
    686688#endif
    687       && (base == 16 && (cp == start_of_digits || TOLOWER (c) != L_('p')))
    688       && (base != 16 && TOLOWER (c) != L_('e')))
     689        /* '0x.' alone is not a valid hexadecimal number.
     690           '.' alone is not valid either, but that has been checked
     691           already earlier.  */
     692        && (base != 16
     693        || cp != start_of_digits
     694        || (cp[decimal_len] >= L_('0') && cp[decimal_len] <= L_('9'))
     695        || ((CHAR_TYPE) TOLOWER (cp[decimal_len]) >= L_('a')
     696            && (CHAR_TYPE) TOLOWER (cp[decimal_len]) <= L_('f'))))
     697    || (base == 16 && (cp != start_of_digits
     698               && (CHAR_TYPE) TOLOWER (c) == L_('p')))
     699    || (base != 16 && (CHAR_TYPE) TOLOWER (c) == L_('e'))))
    689700    {
    690701      tp = correctly_grouped_prefix (start_of_digits, cp, thousands, grouping);
    691702      /* If TP is at the start of the digits, there was no correctly