[PATCH v2] string: Fix OOB read on generic strncmp
Adhemerval Zanella Netto
Thu Feb 23 18:15:09 GMT 2023
On 22/02/23 14:21, Szabolcs Nagy wrote:
> The 02/22/2023 13:31, Adhemerval Zanella wrote:
>> For unaligned case, reading ahead can only be done if parting reads
>> matches the aligned input.
>> Also extend the stratcliff tests to check such cases.
>> Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu,
>> and powerpc-linux-gnu by removing the arch-specific assembly
>> implementation and disabling multi-arch (it covers both LE and BE
>> for 64 and 32 bits).
> thanks this looks good.
> Reviewed-by: Szabolcs Nagy <firstname.lastname@example.org>
So before I push the fix along with the testcase, I checked all strncmp
optimization and found out that some implementations also do not handle
this correctly as expected:
(the ? are implementations that I can really test, even qemu static
thrown illegal instruction).
Noah has brought to my attention that he tried to add similar tests,
but they were rejected by strncmp string must be null-terminated .
The working drafts for C standard I have access (n1256.pdf for C99 and
n3047.pdf for c2x) do not say possibly null-terminated array (as some
stackoverflow answer state ) they refer only as array. So I tend
to follow Florian understanding that strncmp inputs should be NULL
So should we really consider this a OOB read on generic strncmp?
More information about the Libc-alpha