[PATCH v3] stdio-common: Reject insufficient character data in scanf [BZ #12701]
Florian Weimer
fweimer@redhat.com
Mon Sep 1 16:27:24 GMT 2025
* Maciej W. Rozycki:
> Reject invalid formatted scanf character data with the 'c' conversion
> where there is not enough input available to satisfy the field width
> requested. It is required by ISO C that this conversion matches a
> sequence of characters of exactly the number specified by the field
> width and it is also already documented as such in our own manual:
>
> "It reads precisely the next N characters, and fails if it cannot get
> that many."
>
> Currently a matching success is instead incorrectly produced where the
> EOF condition is encountered before the required number of characters
> has been retrieved, and the characters actually obtained are stored in
> the buffer provided.
>
> Add test cases accordingly and remove placeholders from 'c' conversion
> input data for the existing scanf tests.
>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This reportedly broke the dmstats tool in lvm2:
glibc: sscanf parsing of %XXXc is not being returned as read
<https://bugzilla.redhat.com/show_bug.cgi?id=2392416>
I don't know how common it is to use %NNNc where %NNNs was meant. It
may not be possible to release with this change.
Thanks,
Florian
More information about the Libc-alpha
mailing list