1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

stdio-common: Reject real data w/o exponent digits in scanf [BZ #12701]

Reject invalid formatted scanf real input data the exponent part of
which is comprised of an exponent introducing character, optionally
followed by a sign, and with no actual digits following.  Such data is a
prefix of, but not a matching input sequence and it is required by ISO C
to cause a matching failure.

Currently a matching success is instead incorrectly produced along with
the conversion result according to the input significand read and the
exponent of zero, with the significand and the exponent part wholly
consumed from input.

Correct an invalid `tstscanf.c' test accordingly that expects a matching
success for input data provided in the ISO C standard as an example for
a matching failure.

Enable input data that causes test failures without this fix in place.

Reviewed-by: Joseph Myers <josmyers@redhat.com>
This commit is contained in:
Maciej W. Rozycki
2025-03-28 12:35:53 +00:00
parent 0b390b5508
commit 0a8e7ac95c
38 changed files with 2338 additions and 2335 deletions

View File

@@ -151,7 +151,7 @@ main (int argc, char **argv)
{ 2, -12.8F, "degrees", "" },
{ 0, 0.0F, "", "" },
{ 3, 10.0F, "LBS", "fertilizer" },
{ 3, 100.0F, "rgs", "energy" },
{ 0, 0.0F, "", "" },
{ -1, 0.0F, "", "" }};
size_t rounds = 0;
float quant;

View File

@@ -2204,6 +2204,7 @@ digits_extended_fail:
{
char_buffer_add (&charbuf, exp_char);
got_e = got_dot = 1;
got_digit = 0;
}
else
{
@@ -2553,11 +2554,13 @@ digits_extended_fail:
/* Have we read any character? If we try to read a number
in hexadecimal notation and we have read only the `0x'
prefix this is an error. */
prefix this is an error. Also it is an error where we
have read no digits after the exponent character. */
if (__glibc_unlikely (char_buffer_size (&charbuf) == got_sign
|| ((flags & HEXA_FLOAT)
&& (char_buffer_size (&charbuf)
== 2 + got_sign))))
== 2 + got_sign)))
|| (got_e && !got_digit))
conv_error ();
scan_float: