diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc index 24e5dc0fb22f..dd4dab07b3c6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc @@ -67,6 +67,10 @@ static const char *maybe_parse_length_modifier(const char *p, char ll[2]) { // Returns true if the character is an integer conversion specifier. static bool format_is_integer_conv(char c) { +#if SANITIZER_GLIBC + if (char_is_one_of(c, "bB")) + return true; +#endif return char_is_one_of(c, "diouxXn"); } diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp index 18f5da2f23b1..9f7486529cd5 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp @@ -131,7 +131,6 @@ TEST(SanitizerCommonInterceptors, Scanf) { testScanf("a%%%%b", 0); testScanf("a%%b%%", 0); testScanf("a%%%%%%b", 0); - testScanf("a%%%%%b", 0); testScanf("a%%%%%f", 1, F); testScanf("a%%%lxb", 1, L); testScanf("a%lf%%%lxb", 2, D, L); @@ -207,6 +206,14 @@ TEST(SanitizerCommonInterceptors, Scanf) { testScanfPartial("%d%n%n%d %s %s", 3, 5, I, I, I, I, test_buf_size); testScanfPartial("%d%n%n%d %s %s", 4, 6, I, I, I, I, test_buf_size, test_buf_size); + +#if defined(__GLIBC__) + testScanf("%b", 1, I); + testScanf("%zb", 1, Z); + testScanf("a%%%%%b", 1, I); +#else + testScanf("a%%%%%b", 0); +#endif } TEST(SanitizerCommonInterceptors, ScanfAllocate) {