From 1034d41c8fe7b31ba8ba304d1fff93cecb183520 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Thu, 31 Oct 2013 12:51:03 +0100 Subject: [PATCH] Fix parsing of 0e+0 as float --- ChangeLog | 7 +++++++ NEWS | 2 +- stdio-common/tst-sscanf.c | 34 ++++++++++++++++++++++++++++++++++ stdio-common/vfscanf.c | 2 ++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b0cab3f7786..c83db92cd8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-10-31 Andreas Schwab + + [BZ# 15917] + * stdio-common/vfscanf.c (_IO_vfwscanf): Handle leading '0' not + followed by 'x' as part of digit sequence. + * stdio-common/tst-sscanf.c (double_tests2): New tests. + 2013-10-04 Adhemerval Zanella * sysdeps/powerpc/powerpc64/strcpy.S (strcpy): Add word load/store diff --git a/NEWS b/NEWS index f0a93464e0b..2970338bf86 100644 --- a/NEWS +++ b/NEWS @@ -23,7 +23,7 @@ Version 2.18 15465, 15480, 15485, 15488, 15490, 15492, 15493, 15497, 15506, 15522, 15529, 15532, 15536, 15553, 15577, 15583, 15618, 15627, 15631, 15654, 15655, 15666, 15667, 15674, 15711, 15755, 15759, 15797, 15892, 15893, - 15895, 15988, 16072. + 15895, 15917, 15988, 16072. * CVE-2013-2207 Incorrectly granting access to another user's pseudo-terminal has been fixed by disabling the use of pt_chown (Bugzilla #15755). diff --git a/stdio-common/tst-sscanf.c b/stdio-common/tst-sscanf.c index 1edb2271992..3c34f58a635 100644 --- a/stdio-common/tst-sscanf.c +++ b/stdio-common/tst-sscanf.c @@ -109,6 +109,19 @@ struct test double_tests[] = { L("-inf"), L("%g"), 1 } }; +struct test2 +{ + const CHAR *str; + const CHAR *fmt; + int retval; + char residual; +} double_tests2[] = +{ + { L("0e+0"), L("%g%c"), 1, 0 }, + { L("0xe+0"), L("%g%c"), 2, '+' }, + { L("0x.e+0"), L("%g%c"), 2, '+' }, +}; + int main (void) { @@ -196,5 +209,26 @@ main (void) } } + for (i = 0; i < sizeof (double_tests2) / sizeof (double_tests2[0]); ++i) + { + double dummy; + int ret; + char c = 0; + + if ((ret = SSCANF (double_tests2[i].str, double_tests2[i].fmt, + &dummy, &c)) != double_tests2[i].retval) + { + printf ("double_tests2[%d] returned %d != %d\n", + i, ret, double_tests2[i].retval); + result = 1; + } + else if (ret == 2 && c != double_tests2[i].residual) + { + printf ("double_tests2[%d] stopped at '%c' != '%c'\n", + i, c, double_tests2[i].residual); + result = 1; + } + } + return result; } diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index 343056769eb..093c8b0c580 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -1966,6 +1966,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, if (width > 0) --width; } + else + got_digit = 1; } while (1) -- 2.47.2