forked from OSchip/llvm-project
AddressSanitizer: remove match_output.py, split expected output into OS-specific and OS-independent parts
llvm-svn: 150384
This commit is contained in:
parent
0c65064dbe
commit
633c8be0ae
|
@ -29,6 +29,6 @@ int main(int argc, char **argv) {
|
|||
#include <stdio.h>
|
||||
int main() {
|
||||
printf("PASSED\n");
|
||||
// CHECK: PASSED
|
||||
// Check-Common: PASSED
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
// CHECK: AddressSanitizer global-buffer-overflow
|
||||
// Check-Common: AddressSanitizer global-buffer-overflow
|
||||
int global[10];
|
||||
// CHECK: {{#0.*call4}}
|
||||
// Check-Common: {{#0.*call4}}
|
||||
void __attribute__((noinline)) call4(int i) { global[i+10]++; }
|
||||
// CHECK: {{#1.*call3}}
|
||||
// Check-Common: {{#1.*call3}}
|
||||
void __attribute__((noinline)) call3(int i) { call4(i); }
|
||||
// CHECK: {{#2.*call2}}
|
||||
// Check-Common: {{#2.*call2}}
|
||||
void __attribute__((noinline)) call2(int i) { call3(i); }
|
||||
// CHECK: {{#3.*call1}}
|
||||
// Check-Common: {{#3.*call1}}
|
||||
void __attribute__((noinline)) call1(int i) { call2(i); }
|
||||
// CHECK: {{#4.*main}}
|
||||
// Check-Common: {{#4.*main}}
|
||||
int main(int argc, char **argv) {
|
||||
call1(argc);
|
||||
return global[0];
|
||||
|
|
|
@ -69,6 +69,6 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
addr[1] = 2; // BOOM (if the bug is not fixed).
|
||||
printf("PASS\n");
|
||||
// CHECK: PASS
|
||||
// Check-Common: PASS
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ int main(int argc, char **argv) {
|
|||
memset(YYY, 0, 10);
|
||||
memset(ZZZ, 0, 10);
|
||||
int res = YYY[argc * 10]; // BOOOM
|
||||
// CHECK: {{READ of size 1 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in main .*global-overflow.cc:9}}
|
||||
// CHECK: {{0x.* is located 0 bytes to the right of global variable .*YYY.* of size 10}}
|
||||
// Check-Common: {{READ of size 1 at 0x.* thread T0}}
|
||||
// Check-Common: {{ #0 0x.* in main .*global-overflow.cc:9}}
|
||||
// Check-Common: {{0x.* is located 0 bytes to the right of global variable .*YYY.* of size 10}}
|
||||
res += XXX[argc] + ZZZ[argc];
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -8,18 +8,15 @@ int main(int argc, char **argv) {
|
|||
return res;
|
||||
}
|
||||
|
||||
// CHECK: {{READ of size 1 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in main .*heap-overflow.cc:6}}
|
||||
// CHECK: {{0x.* is located 0 bytes to the right of 10-byte region}}
|
||||
// CHECK: {{allocated by thread T0 here:}}
|
||||
// CHECK: {{ #0 0x.* in malloc}}
|
||||
// CHECK: {{ #1 0x.* in main .*heap-overflow.cc:[45]}}
|
||||
// Check-Common: {{READ of size 1 at 0x.* thread T0}}
|
||||
// Check-Common: {{ #0 0x.* in main .*heap-overflow.cc:6}}
|
||||
// Check-Common: {{0x.* is located 0 bytes to the right of 10-byte region}}
|
||||
// Check-Common: {{allocated by thread T0 here:}}
|
||||
|
||||
// Darwin: {{READ of size 1 at 0x.* thread T0}}
|
||||
// Darwin: {{ #0 0x.* in main .*heap-overflow.cc:6}}
|
||||
// Darwin: {{0x.* is located 0 bytes to the right of 10-byte region}}
|
||||
// Darwin: {{allocated by thread T0 here:}}
|
||||
// Darwin: {{ #0 0x.* in .*mz_malloc.*}}
|
||||
// Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
|
||||
// Darwin: {{ #2 0x.* in malloc.*}}
|
||||
// Darwin: {{ #3 0x.* in main heap-overflow.cc:[45]}}
|
||||
// Check-Linux: {{ #0 0x.* in malloc}}
|
||||
// Check-Linux: {{ #1 0x.* in main .*heap-overflow.cc:[45]}}
|
||||
|
||||
// Check-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
|
||||
// Check-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
|
||||
// Check-Darwin: {{ #2 0x.* in malloc.*}}
|
||||
// Check-Darwin: {{ #3 0x.* in main heap-overflow.cc:[45]}}
|
||||
|
|
|
@ -32,11 +32,11 @@ int main(int argc, char **argv) {
|
|||
delete x;
|
||||
}
|
||||
|
||||
// CHECK: {{.*ERROR: AddressSanitizer heap-buffer-overflow on address 0x.* at pc 0x.* bp 0x.* sp 0x.*}}
|
||||
// CHECK: {{READ of size 4 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in LargeFunction .*large_func_test.cc:15}}
|
||||
// CHECK: {{ #1 0x.* in main .*large_func_test.cc:3[012]}}
|
||||
// CHECK: {{0x.* is located 44 bytes to the right of 400-byte region}}
|
||||
// CHECK: {{allocated by thread T0 here:}}
|
||||
// CHECK: {{ #0 0x.* in operator new.*}}
|
||||
// CHECK: {{ #1 0x.* in main .*large_func_test.cc:30}}
|
||||
// Check-Common: {{.*ERROR: AddressSanitizer heap-buffer-overflow on address 0x.* at pc 0x.* bp 0x.* sp 0x.*}}
|
||||
// Check-Common: {{READ of size 4 at 0x.* thread T0}}
|
||||
// Check-Common: {{ #0 0x.* in LargeFunction .*large_func_test.cc:15}}
|
||||
// Check-Common: {{ #1 0x.* in main .*large_func_test.cc:3[012]}}
|
||||
// Check-Common: {{0x.* is located 44 bytes to the right of 400-byte region}}
|
||||
// Check-Common: {{allocated by thread T0 here:}}
|
||||
// Check-Common: {{ #0 0x.* in operator new.*}}
|
||||
// Check-Common: {{ #1 0x.* in main .*large_func_test.cc:30}}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
def matchFile(f, f_re):
|
||||
for line_re in f_re:
|
||||
line_re = line_re.rstrip()
|
||||
if not line_re:
|
||||
continue
|
||||
if line_re[0] == '#':
|
||||
continue
|
||||
match = False
|
||||
for line in f:
|
||||
line = line.rstrip()
|
||||
# print line
|
||||
if re.search(line_re, line):
|
||||
match = True
|
||||
#print 'match: %s =~ %s' % (line, line_re)
|
||||
break
|
||||
if not match:
|
||||
print 'no match for: %s' % (line_re)
|
||||
return False
|
||||
return True
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print >>sys.stderr, 'Usage: %s <template file>'
|
||||
sys.exit(1)
|
||||
|
||||
f = sys.stdin
|
||||
f_re = open(sys.argv[1])
|
||||
|
||||
if not matchFile(f, f_re):
|
||||
print >>sys.stderr, 'File does not match the template'
|
||||
sys.exit(1)
|
|
@ -6,13 +6,11 @@ int main() {
|
|||
NullDeref((int*)0);
|
||||
}
|
||||
|
||||
// CHECK: {{.*ERROR: AddressSanitizer crashed on unknown address 0x0*00028 .*pc 0x.*}}
|
||||
// CHECK: {{AddressSanitizer can not provide additional info. ABORTING}}
|
||||
// CHECK: {{ #0 0x.* in NullDeref.*null_deref.cc:3}}
|
||||
// CHECK: {{ #1 0x.* in main.*null_deref.cc:[67]}}
|
||||
// Check-Common: {{.*ERROR: AddressSanitizer crashed on unknown address 0x0*00028 .*pc 0x.*}}
|
||||
// Check-Common: {{AddressSanitizer can not provide additional info. ABORTING}}
|
||||
|
||||
// Darwin: {{.*ERROR: AddressSanitizer crashed on unknown address 0x0*00028 .*pc 0x.*}}
|
||||
// Darwin: {{AddressSanitizer can not provide additional info. ABORTING}}
|
||||
// atos cannot resolve the file:line info for frame 0 on the O1 level
|
||||
// Darwin: {{ #0 0x.* in NullDeref.*}}
|
||||
// Darwin: {{ #1 0x.* in main.*null_deref.cc:[67]}}
|
||||
// atos on Mac cannot resolve the file:line info for frame 0 on the O1 level
|
||||
// Check-Linux: {{ #0 0x.* in NullDeref.*null_deref.cc:3}}
|
||||
// Check-Darwin: {{ #0 0x.* in NullDeref.*}}
|
||||
|
||||
// Check-Common: {{ #1 0x.* in main.*null_deref.cc:[67]}}
|
||||
|
|
|
@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// CHECK: {{.*ERROR: AddressSanitizer global-buffer-overflow}}
|
||||
// CHECK: {{READ of size 4 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.*}}
|
||||
// CHECK: {{ #1 0x.* in main .*shared-lib-test.cc:3[567]}}
|
||||
// Check-Common: {{.*ERROR: AddressSanitizer global-buffer-overflow}}
|
||||
// Check-Common: {{READ of size 4 at 0x.* thread T0}}
|
||||
// Check-Common: {{ #0 0x.*}}
|
||||
// Check-Common: {{ #1 0x.* in main .*shared-lib-test.cc:3[567]}}
|
||||
|
|
|
@ -6,6 +6,6 @@ int main(int argc, char **argv) {
|
|||
return res;
|
||||
}
|
||||
|
||||
// CHECK: {{READ of size 1 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in main .*stack-overflow.cc:5}}
|
||||
// CHECK: {{Address 0x.* is .* frame <main>}}
|
||||
// Check-Common: {{READ of size 1 at 0x.* thread T0}}
|
||||
// Check-Common: {{ #0 0x.* in main .*stack-overflow.cc:5}}
|
||||
// Check-Common: {{Address 0x.* is .* frame <main>}}
|
||||
|
|
|
@ -16,9 +16,9 @@ __attribute__((noinline))
|
|||
void Func2(char *x) {
|
||||
fprintf(stderr, "2: %p\n", x);
|
||||
*x = 1;
|
||||
// CHECK: {{WRITE of size 1 .* thread T0}}
|
||||
// CHECK: {{ #0.*Func2.*stack-use-after-return.cc:18}}
|
||||
// CHECK: {{is located in frame <.*Func1.*> of T0's stack}}
|
||||
// Check-Common: {{WRITE of size 1 .* thread T0}}
|
||||
// Check-Common: {{ #0.*Func2.*stack-use-after-return.cc:18}}
|
||||
// Check-Common: {{is located in frame <.*Func1.*> of T0's stack}}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
|
@ -8,20 +8,17 @@ int main(int argc, char **argv) {
|
|||
return short_buffer[8];
|
||||
}
|
||||
|
||||
// CHECK: {{WRITE of size 1 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in strncpy}}
|
||||
// CHECK: {{ #1 0x.* in main .*strncpy-overflow.cc:[78]}}
|
||||
// CHECK: {{0x.* is located 0 bytes to the right of 9-byte region}}
|
||||
// CHECK: {{allocated by thread T0 here:}}
|
||||
// CHECK: {{ #0 0x.* in malloc}}
|
||||
// CHECK: {{ #1 0x.* in main .*strncpy-overflow.cc:6}}
|
||||
// Check-Common: {{WRITE of size 1 at 0x.* thread T0}}
|
||||
// Check-Linux: {{ #0 0x.* in strncpy}}
|
||||
// Check-Darwin: {{ #0 0x.* in wrap_strncpy}}
|
||||
// Check-Common: {{ #1 0x.* in main .*strncpy-overflow.cc:[78]}}
|
||||
// Check-Common: {{0x.* is located 0 bytes to the right of 9-byte region}}
|
||||
// Check-Common: {{allocated by thread T0 here:}}
|
||||
|
||||
// Darwin: {{WRITE of size 1 at 0x.* thread T0}}
|
||||
// Darwin: {{ #0 0x.* in wrap_strncpy}}
|
||||
// Darwin: {{ #1 0x.* in main .*strncpy-overflow.cc:[78]}}
|
||||
// Darwin: {{0x.* is located 0 bytes to the right of 9-byte region}}
|
||||
// Darwin: {{allocated by thread T0 here:}}
|
||||
// Darwin: {{ #0 0x.* in .*mz_malloc.*}}
|
||||
// Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
|
||||
// Darwin: {{ #2 0x.* in malloc.*}}
|
||||
// Darwin: {{ #3 0x.* in main .*strncpy-overflow.cc:6}}
|
||||
// Check-Linux: {{ #0 0x.* in malloc}}
|
||||
// Check-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:6}}
|
||||
|
||||
// Check-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
|
||||
// Check-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
|
||||
// Check-Darwin: {{ #2 0x.* in malloc.*}}
|
||||
// Check-Darwin: {{ #3 0x.* in main .*strncpy-overflow.cc:6}}
|
||||
|
|
|
@ -8,28 +8,27 @@ CC=$2
|
|||
FILE_CHECK=$3
|
||||
CXXFLAGS="-mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls"
|
||||
SYMBOLIZER=../scripts/asan_symbolize.py
|
||||
TMP_ASAN_REPORT=/tmp/asan_report
|
||||
|
||||
# check_program exe_file src_file [check_prefix]
|
||||
run_program() {
|
||||
./$1 2>&1 | $SYMBOLIZER 2> /dev/null | c++filt > $TMP_ASAN_REPORT
|
||||
}
|
||||
|
||||
# check_program exe_file source_file check_prefix
|
||||
check_program() {
|
||||
exe=$1
|
||||
src=$2
|
||||
prefix="CHECK"
|
||||
if [ "z$3" != "z" ] ; then
|
||||
prefix=$3
|
||||
fi
|
||||
./$exe 2>&1 | $SYMBOLIZER 2> /dev/null | c++filt | \
|
||||
$FILE_CHECK $src --check-prefix=$prefix
|
||||
run_program $1
|
||||
$FILE_CHECK $2 --check-prefix=$3 < $TMP_ASAN_REPORT
|
||||
}
|
||||
|
||||
C_TEST=use-after-free
|
||||
echo "Sanity checking a test in pure C"
|
||||
$CC -g -faddress-sanitizer -O2 $C_TEST.c
|
||||
check_program a.out $C_TEST.c
|
||||
check_program a.out $C_TEST.c CHECK
|
||||
rm ./a.out
|
||||
|
||||
echo "Sanity checking a test in pure C with -pie"
|
||||
$CC -g -faddress-sanitizer -O2 $C_TEST.c -pie
|
||||
check_program a.out $C_TEST.c
|
||||
check_program a.out $C_TEST.c CHECK
|
||||
rm ./a.out
|
||||
|
||||
echo "Testing sleep_before_dying"
|
||||
|
@ -55,15 +54,14 @@ for t in *.cc; do
|
|||
[ "$DEBUG" == "1" ] && echo $build_command
|
||||
$build_command
|
||||
[ -e "$c_so.cc" ] && $CXX $CXXFLAGS -g -m$b -faddress-sanitizer -O$O $c_so.cc -fPIC -shared -o $so
|
||||
# If there's an OS-specific template, use it.
|
||||
# Otherwise use default template.
|
||||
if [ `grep -c "$OS" $c.cc` -gt 0 ]
|
||||
run_program $exe
|
||||
# Check common expected lines for OS.
|
||||
$FILE_CHECK $c.cc --check-prefix="Check-Common" < $TMP_ASAN_REPORT
|
||||
# Check OS-specific lines.
|
||||
if [ `grep -c "Check-$OS" $c.cc` -gt 0 ]
|
||||
then
|
||||
check_prefix="$OS"
|
||||
else
|
||||
check_prefix="CHECK"
|
||||
$FILE_CHECK $c.cc --check-prefix="Check-$OS" < $TMP_ASAN_REPORT
|
||||
fi
|
||||
check_program $exe $c.cc $check_prefix
|
||||
rm ./$exe
|
||||
[ -e "$so" ] && rm ./$so
|
||||
done
|
||||
|
|
|
@ -5,28 +5,26 @@ int main() {
|
|||
return x[5];
|
||||
}
|
||||
|
||||
// CHECK: {{.*ERROR: AddressSanitizer heap-use-after-free on address 0x.* at pc 0x.* bp 0x.* sp 0x.*}}
|
||||
// CHECK: {{READ of size 1 at 0x.* thread T0}}
|
||||
// CHECK: {{ #0 0x.* in main .*use-after-free.cc:5}}
|
||||
// CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
|
||||
// CHECK: {{freed by thread T0 here:}}
|
||||
// CHECK: {{ #0 0x.* in free}}
|
||||
// CHECK: {{ #1 0x.* in main .*use-after-free.cc:[45]}}
|
||||
// CHECK: {{previously allocated by thread T0 here:}}
|
||||
// CHECK: {{ #0 0x.* in malloc}}
|
||||
// CHECK: {{ #1 0x.* in main .*use-after-free.cc:3}}
|
||||
// Check-Common: {{.*ERROR: AddressSanitizer heap-use-after-free on address 0x.* at pc 0x.* bp 0x.* sp 0x.*}}
|
||||
// Check-Common: {{READ of size 1 at 0x.* thread T0}}
|
||||
// Check-Common: {{ #0 0x.* in main .*use-after-free.cc:5}}
|
||||
// Check-Common: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
|
||||
// Check-Common: {{freed by thread T0 here:}}
|
||||
|
||||
// Darwin: {{.*ERROR: AddressSanitizer heap-use-after-free on address 0x.* at pc 0x.* bp 0x.* sp 0x.*}}
|
||||
// Darwin: {{READ of size 1 at 0x.* thread T0}}
|
||||
// Darwin: {{ #0 0x.* in main .*use-after-free.cc:5}}
|
||||
// Darwin: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
|
||||
// Darwin: {{freed by thread T0 here:}}
|
||||
// Darwin: {{ #0 0x.* in .*mz_free.*}}
|
||||
// Check-Linux: {{ #0 0x.* in free}}
|
||||
// Check-Linux: {{ #1 0x.* in main .*use-after-free.cc:[45]}}
|
||||
|
||||
// Check-Darwin: {{ #0 0x.* in .*mz_free.*}}
|
||||
// We override free() on Darwin, thus no malloc_zone_free
|
||||
// Darwin: {{ #1 0x.* in free}}
|
||||
// Darwin: {{ #2 0x.* in main .*use-after-free.cc:[45]}}
|
||||
// Darwin: {{previously allocated by thread T0 here:}}
|
||||
// Darwin: {{ #0 0x.* in .*mz_malloc.*}}
|
||||
// Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
|
||||
// Darwin: {{ #2 0x.* in malloc.*}}
|
||||
// Darwin: {{ #3 0x.* in main .*use-after-free.cc:3}}
|
||||
// Check-Darwin: {{ #1 0x.* in free}}
|
||||
// Check-Darwin: {{ #2 0x.* in main .*use-after-free.cc:[45]}}
|
||||
|
||||
// Check-Common: {{previously allocated by thread T0 here:}}
|
||||
|
||||
// Check-Linux: {{ #0 0x.* in malloc}}
|
||||
// Check-Linux: {{ #1 0x.* in main .*use-after-free.cc:3}}
|
||||
|
||||
// Check-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
|
||||
// Check-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
|
||||
// Check-Darwin: {{ #2 0x.* in malloc.*}}
|
||||
// Check-Darwin: {{ #3 0x.* in main .*use-after-free.cc:3}}
|
||||
|
|
Loading…
Reference in New Issue