[compiler-rt] 79cd6c3 - [dfsan] Add test case for sscanf (#94700)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 17:48:41 PDT 2024


Author: Thurston Dang
Date: 2024-06-06T17:48:37-07:00
New Revision: 79cd6c3d01c6c69ca870418a3c602dbd1bef29e4

URL: https://github.com/llvm/llvm-project/commit/79cd6c3d01c6c69ca870418a3c602dbd1bef29e4
DIFF: https://github.com/llvm/llvm-project/commit/79cd6c3d01c6c69ca870418a3c602dbd1bef29e4.diff

LOG: [dfsan] Add test case for sscanf (#94700)

This test case shows a limitation of DFSan's sscanf implementation
(introduced in https://reviews.llvm.org/D153775): it simply ignores
ordinary characters in the format string, instead of actually comparing
them against the input. This may change the semantics of instrumented
programs.

Importantly, this also means that DFSan's release_shadow_space.c test,
which relies on sscanf to scrape the RSS from /proc/maps output, will
incorrectly match lines that don't contain RSS information. As a result,
it adding together numbers from irrelevant output (e.g., base
addresses), resulting in test flakiness
(https://github.com/llvm/llvm-project/issues/91287).

Added: 
    compiler-rt/test/dfsan/sscanf.c

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/dfsan/sscanf.c b/compiler-rt/test/dfsan/sscanf.c
new file mode 100644
index 0000000000000..dbc2de4ba96c1
--- /dev/null
+++ b/compiler-rt/test/dfsan/sscanf.c
@@ -0,0 +1,19 @@
+// RUN: %clang_dfsan %s -o %t && %run %t
+// XFAIL: *
+
+#include <assert.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+  char buf[256] = "10000000000-100000000000 rw-p 00000000 00:00 0";
+  long rss = 0;
+  // This test exposes a bug in DFSan's sscanf, that leads to flakiness
+  // in release_shadow_space.c (see
+  // https://github.com/llvm/llvm-project/issues/91287)
+  if (sscanf(buf, "Garbage text before, %ld, Garbage text after", &rss) == 1) {
+    printf("Error: matched %ld\n", rss);
+    return 1;
+  }
+
+  return 0;
+}


        


More information about the llvm-commits mailing list