[COMMITTED 2.44] stdio-common: Fix double null terminator in wide scanf %s and %[ (BZ 34989, CVE-2026-115819)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Nov 16 21:49:12 GMT 2026
On 16/11/26 17:29, Aurelien Jarno wrote:
> Hi Adhemerval,
>
> On 2026-11-16 08:46, Adhemerval Zanella Netto wrote:
>>
>>
>> On 15/11/26 17:12, Aurelien Jarno wrote:
>>> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>>>
>>> For %s and %[ without the 'l' modifier, the wide scanf functions
>>> convert the input into the char array with __wcrtomb. To emit the
>>> sequence that returns to the initial shift state, the conversion is
>>> finished with __wcrtomb (buf, L'\0', &state), which also stores the
>>> terminating null byte, and the N bytes are copied to the output. The
>>> code then appends another null byte, so two are written.
>>>
>>> If the input fills the field width, an array sized for the converted
>>> string plus its terminator (as C requires) is written one byte past
>>> its end, for instance:
>>>
>>> char buf[5];
>>> swscanf (L"abcd", L"%4s", buf);
>>>
>>> stores "abcd\0\0". The 'm' modifier allocated one extra byte for it,
>>> which was later trimmed.
>>>
>>> Only append the null byte explicitly for the narrow scanf, and size
>>> the 'm' buffer for the N bytes from __wcrtomb.
>>>
>>> The new test checks swscanf and fwscanf with the destination placed
>>> right before a PROT_NONE page, in the C and a UTF-8 locale, and the
>>> 'm' modifier allocation for a range of string lengths.
>>>
>>> Checked on x86_64-linux-gnu.
>>>
>>> Reported-by: Russell Miller <rmiller@duskglow.com>
>>> (cherry picked from commit 3ccbe46830772e17c460a1d28a884a7c59b03d35)
>>
>> Thanks, I was about to do that.
>
> Oops sorry for the collision.
>
>> Only one nit: usually we also add the fixed
>> bug on the NEWS entry:
>
>> [34989] stdio: Wide scanf %s and %[ write an extra null byte past the
>> destination (CVE-2026-115819)
>
> Ok. It seems it is not done systematically also by others, so 12 entries
> were actually missing. I also noticed that some of the one that got
> backported were not closed and/or marked with target milestone 2.45 in
> bugzilla, so were not found by the list-fixed-bugs.py source.
>
> I have just added the missing ones on the 2.44 branch. I'll do the same
> for the 2.41, 2.42 and 2.43 branches later.
Thanks for checking on this. Maybe we can add a script to make it easier
to update the NEWS entry.
More information about the Libc-stable
mailing list