[all-commits] [llvm/llvm-project] 0afe6e: [libc] Scanf shouldn't match just "0x" for hex int...
Michael Jones via All-commits
all-commits at lists.llvm.org
Fri Oct 18 15:48:36 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0afe6e42fbab25b3b0d35921774bf2584bcd0d74
https://github.com/llvm/llvm-project/commit/0afe6e42fbab25b3b0d35921774bf2584bcd0d74
Author: Michael Jones <michaelrj at google.com>
Date: 2024-10-18 (Fri, 18 Oct 2024)
Changed paths:
M libc/src/stdio/scanf_core/int_converter.cpp
M libc/test/src/stdio/sscanf_test.cpp
Log Message:
-----------
[libc] Scanf shouldn't match just "0x" for hex int (#112440)
Scanf parsing reads the longest possibly valid prefix for a given
conversion. Then, it performs the conversion on that string. In the case
of "0xZ" with a hex conversion (either "%x" or "%i") the longest
possibly valid prefix is "0x", which makes it the "input item" (per the
standard). The sequence "0x" is not a "matching sequence" for a hex
conversion, meaning it results in a matching failure, and parsing ends.
This is because to know that there's no valid digit after "0x" it reads
the 'Z', but it can only put back one character (the 'Z') leaving it
with consuming an invalid sequence.
(inspired by a thread on the libc-coord mailing list:
https://www.openwall.com/lists/libc-coord/2024/10/15/1, see 7.32.6.2 in
the standard for more details.)
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list