Skip to content

[sanitizer] Support "bB" printf GLIBC extension #128449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Feb 24, 2025

https://www.gnu.org/software/libc/manual/html_node/Table-of-Output-Conversions.html

Without the patch llc triggers non-fatal Asan warning.

Created using spr 1.3.4
@vitalybuka vitalybuka changed the title [sanitizer] Support "bB" GLIBC extension [sanitizer] Support "bB" printf GLIBC extension Feb 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 24, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

https://www.gnu.org/software/libc/manual/html_node/Table-of-Output-Conversions.html

Without the patch llc triggers non-fatal
Asan warning.


Full diff: https://github.com/llvm/llvm-project/pull/128449.diff

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc (+4)
  • (modified) compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp (+8-1)
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 24e5dc0fb22f5..dd4dab07b3c69 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 de96e573ab844..751cf866553ca 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
@@ -128,7 +128,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);
@@ -204,6 +203,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) {

@vitalybuka vitalybuka requested a review from thurstond February 24, 2025 01:22
Created using spr 1.3.4
@vitalybuka vitalybuka merged commit 8b1d384 into main Feb 24, 2025
10 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/sanitizer-support-bb-glibc-extension branch February 24, 2025 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants