Skip to content

Commit 8b1d384

Browse files
authored
[sanitizer] Support "bB" printf GLIBC extension (#128449)
https://www.gnu.org/software/libc/manual/html_node/Table-of-Output-Conversions.html Without the patch llc triggers non-fatal Asan warning.
1 parent 3aef599 commit 8b1d384

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ static const char *maybe_parse_length_modifier(const char *p, char ll[2]) {
6767

6868
// Returns true if the character is an integer conversion specifier.
6969
static bool format_is_integer_conv(char c) {
70+
#if SANITIZER_GLIBC
71+
if (char_is_one_of(c, "bB"))
72+
return true;
73+
#endif
7074
return char_is_one_of(c, "diouxXn");
7175
}
7276

compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ TEST(SanitizerCommonInterceptors, Scanf) {
131131
testScanf("a%%%%b", 0);
132132
testScanf("a%%b%%", 0);
133133
testScanf("a%%%%%%b", 0);
134-
testScanf("a%%%%%b", 0);
135134
testScanf("a%%%%%f", 1, F);
136135
testScanf("a%%%lxb", 1, L);
137136
testScanf("a%lf%%%lxb", 2, D, L);
@@ -207,6 +206,14 @@ TEST(SanitizerCommonInterceptors, Scanf) {
207206
testScanfPartial("%d%n%n%d %s %s", 3, 5, I, I, I, I, test_buf_size);
208207
testScanfPartial("%d%n%n%d %s %s", 4, 6, I, I, I, I, test_buf_size,
209208
test_buf_size);
209+
210+
#if defined(__GLIBC__)
211+
testScanf("%b", 1, I);
212+
testScanf("%zb", 1, Z);
213+
testScanf("a%%%%%b", 1, I);
214+
#else
215+
testScanf("a%%%%%b", 0);
216+
#endif
210217
}
211218

212219
TEST(SanitizerCommonInterceptors, ScanfAllocate) {

0 commit comments

Comments
 (0)