[compiler-rt] r250998 - [asan] Get rid of UB in string tests. Patch by Max Ostapenko.
Yury Gribov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 22 01:10:57 PDT 2015
Author: ygribov
Date: Thu Oct 22 03:10:56 2015
New Revision: 250998
URL: http://llvm.org/viewvc/llvm-project?rev=250998&view=rev
Log:
[asan] Get rid of UB in string tests. Patch by Max Ostapenko.
Differential revision: http://reviews.llvm.org/D13895
Modified:
compiler-rt/trunk/test/asan/TestCases/strcasestr-1.c
compiler-rt/trunk/test/asan/TestCases/strcasestr-2.c
compiler-rt/trunk/test/asan/TestCases/strcspn-1.c
compiler-rt/trunk/test/asan/TestCases/strcspn-2.c
compiler-rt/trunk/test/asan/TestCases/strpbrk-1.c
compiler-rt/trunk/test/asan/TestCases/strpbrk-2.c
compiler-rt/trunk/test/asan/TestCases/strspn-1.c
compiler-rt/trunk/test/asan/TestCases/strspn-2.c
compiler-rt/trunk/test/asan/TestCases/strstr-1.c
compiler-rt/trunk/test/asan/TestCases/strstr-2.c
Modified: compiler-rt/trunk/test/asan/TestCases/strcasestr-1.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strcasestr-1.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strcasestr-1.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strcasestr-1.c Thu Oct 22 03:10:56 2015
@@ -11,14 +11,15 @@
#define _GNU_SOURCE
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
char *r = 0;
char s2[] = "c";
- char s1[] = {'a', 'C'};
- char s3 = 0;
+ char s1[4] = "abC";
+ __asan_poison_memory_region ((char *)&s1[2], 2);
r = strcasestr(s1, s2);
- // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
- assert(r == s1 + 1);
+ // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable
+ assert(r == s1 + 2);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strcasestr-2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strcasestr-2.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strcasestr-2.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strcasestr-2.c Thu Oct 22 03:10:56 2015
@@ -11,14 +11,15 @@
#define _GNU_SOURCE
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
char *r = 0;
char s1[] = "ab";
- char s2[] = {'c'};
- char s3 = 0;
+ char s2[4] = "cba";
+ __asan_poison_memory_region ((char *)&s2[2], 2);
r = strcasestr(s1, s2);
assert(r == 0);
- // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strcspn-1.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strcspn-1.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strcspn-1.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strcspn-1.c Thu Oct 22 03:10:56 2015
@@ -6,14 +6,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
size_t r;
char s2[] = "ab";
- char s1[] = {'c', 'a'};
- char s3 = 0;
+ char s1[4] = "caB";
+ __asan_poison_memory_region ((char *)&s1[2], 2);
r = strcspn(s1, s2);
- // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == 1);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strcspn-2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strcspn-2.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strcspn-2.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strcspn-2.c Thu Oct 22 03:10:56 2015
@@ -6,14 +6,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
size_t r;
char s1[] = "ab";
- char s2[] = {'a'};
- char s3 = 0;
+ char s2[4] = "abc";
+ __asan_poison_memory_region ((char *)&s2[2], 2);
r = strcspn(s1, s2);
- // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == 0);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strpbrk-1.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strpbrk-1.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strpbrk-1.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strpbrk-1.c Thu Oct 22 03:10:56 2015
@@ -6,14 +6,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
char *r;
char s2[] = "ab";
- char s1[] = {'c', 'a'};
- char s3 = 0;
+ char s1[4] = "cab";
+ __asan_poison_memory_region ((char *)&s1[2], 2);
r = strpbrk(s1, s2);
- // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == s1 + 1);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strpbrk-2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strpbrk-2.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strpbrk-2.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strpbrk-2.c Thu Oct 22 03:10:56 2015
@@ -6,14 +6,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
char *r;
char s1[] = "c";
- char s2[] = {'b', 'c'};
- char s3 = 0;
+ char s2[4] = "bca";
+ __asan_poison_memory_region ((char *)&s2[2], 2);
r = strpbrk(s1, s2);
- // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == s1);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strspn-1.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strspn-1.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strspn-1.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strspn-1.c Thu Oct 22 03:10:56 2015
@@ -6,14 +6,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
size_t r;
char s2[] = "ab";
- char s1[] = {'a', 'c'};
- char s3 = 0;
+ char s1[4] = "acb";
+ __asan_poison_memory_region ((char *)&s1[2], 2);
r = strspn(s1, s2);
- // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == 1);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strspn-2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strspn-2.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strspn-2.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strspn-2.c Thu Oct 22 03:10:56 2015
@@ -6,14 +6,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
size_t r;
char s1[] = "bbc";
- char s2[] = {'a', 'b'};
- char s3 = 0;
+ char s2[5] = "abcd";
+ __asan_poison_memory_region ((char *)&s2[3], 2);
r = strspn(s1, s2);
- // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r >= 2);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strstr-1.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strstr-1.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strstr-1.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strstr-1.c Thu Oct 22 03:10:56 2015
@@ -7,14 +7,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
char *r = 0;
char s2[] = "c";
- char s1[] = {'a', 'c'};
- char s3 = 0;
+ char s1[4] = "acb";
+ __asan_poison_memory_region ((char *)&s1[2], 2);
r = strstr(s1, s2);
- // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == s1 + 1);
return 0;
}
Modified: compiler-rt/trunk/test/asan/TestCases/strstr-2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strstr-2.c?rev=250998&r1=250997&r2=250998&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strstr-2.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/strstr-2.c Thu Oct 22 03:10:56 2015
@@ -7,14 +7,15 @@
#include <assert.h>
#include <string.h>
+#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
char *r = 0;
char s1[] = "ab";
- char s2[] = {'c'};
- char s3 = 0;
+ char s2[4] = "cab";
+ __asan_poison_memory_region ((char *)&s2[2], 2);
r = strstr(s1, s2);
- // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == 0);
return 0;
}
More information about the llvm-commits
mailing list