Skip to content

Commit 79cd6c3

Browse files
authored
[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 (#91287).
1 parent 5e0fc93 commit 79cd6c3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

compiler-rt/test/dfsan/sscanf.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_dfsan %s -o %t && %run %t
2+
// XFAIL: *
3+
4+
#include <assert.h>
5+
#include <stdio.h>
6+
7+
int main(int argc, char *argv[]) {
8+
char buf[256] = "10000000000-100000000000 rw-p 00000000 00:00 0";
9+
long rss = 0;
10+
// This test exposes a bug in DFSan's sscanf, that leads to flakiness
11+
// in release_shadow_space.c (see
12+
// https://github.com/llvm/llvm-project/issues/91287)
13+
if (sscanf(buf, "Garbage text before, %ld, Garbage text after", &rss) == 1) {
14+
printf("Error: matched %ld\n", rss);
15+
return 1;
16+
}
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)