[compiler-rt] r174971 - [sanitizer] Tests for scanf parser in allowGnuMalloc=false mode.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Tue Feb 12 06:37:56 PST 2013
Author: eugenis
Date: Tue Feb 12 08:37:55 2013
New Revision: 174971
URL: http://llvm.org/viewvc/llvm-project?rev=174971&view=rev
Log:
[sanitizer] Tests for scanf parser in allowGnuMalloc=false mode.
Modified:
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc?rev=174971&r1=174970&r2=174971&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_scanf_interceptor_test.cc Tue Feb 12 08:37:55 2013
@@ -28,21 +28,23 @@ static const char scanf_buf[] = "Test st
static size_t scanf_buf_size = sizeof(scanf_buf);
static const unsigned SCANF_ARGS_MAX = 16;
-static void testScanf3(void *ctx, int result, const char *format, ...) {
+static void testScanf3(void *ctx, int result, bool allowGnuMalloc,
+ const char *format, ...) {
va_list ap;
va_start(ap, format);
- scanf_common(ctx, result, format, ap);
+ scanf_common(ctx, result, allowGnuMalloc, format, ap);
va_end(ap);
}
-static void testScanf2(const char *format, int scanf_result, unsigned n,
+static void testScanf2(const char *format, int scanf_result,
+ bool allowGnuMalloc, unsigned n,
va_list expected_sizes) {
std::vector<unsigned> scanf_sizes;
// 16 args should be enough.
- testScanf3((void *)&scanf_sizes, scanf_result, format, scanf_buf, scanf_buf,
+ testScanf3((void *)&scanf_sizes, scanf_result, allowGnuMalloc, format,
scanf_buf, scanf_buf, scanf_buf, scanf_buf, scanf_buf, scanf_buf,
scanf_buf, scanf_buf, scanf_buf, scanf_buf, scanf_buf, scanf_buf,
- scanf_buf, scanf_buf);
+ scanf_buf, scanf_buf, scanf_buf, scanf_buf);
ASSERT_EQ(n, scanf_sizes.size()) << "Unexpected number of format arguments: '"
<< format << "'";
for (unsigned i = 0; i < n; ++i)
@@ -54,7 +56,7 @@ static void testScanf2(const char *forma
static void testScanf(const char *format, unsigned n, ...) {
va_list ap;
va_start(ap, n);
- testScanf2(format, SCANF_ARGS_MAX, n, ap);
+ testScanf2(format, SCANF_ARGS_MAX, /* allowGnuMalloc */ true, n, ap);
va_end(ap);
}
@@ -62,7 +64,14 @@ static void testScanfPartial(const char
...) {
va_list ap;
va_start(ap, n);
- testScanf2(format, scanf_result, n, ap);
+ testScanf2(format, scanf_result, /* allowGnuMalloc */ true, n, ap);
+ va_end(ap);
+}
+
+static void testScanfNoGnuMalloc(const char *format, unsigned n, ...) {
+ va_list ap;
+ va_start(ap, n);
+ testScanf2(format, SCANF_ARGS_MAX, /* allowGnuMalloc */ false, n, ap);
va_end(ap);
}
@@ -137,6 +146,20 @@ TEST(SanitizerCommonInterceptors, Scanf)
testScanf("%a13S", 1, std::min(F, P));
testScanf("%alS", 1, std::min(F, P));
+ testScanfNoGnuMalloc("s%Las", 1, LD);
+ testScanfNoGnuMalloc("%ar", 1, F);
+ testScanfNoGnuMalloc("%a[", 1, F);
+ testScanfNoGnuMalloc("%a[]", 1, F);
+ testScanfNoGnuMalloc("%a[]]", 1, F);
+ testScanfNoGnuMalloc("%a[abc]", 1, F);
+ testScanfNoGnuMalloc("%a[^abc]", 1, F);
+ testScanfNoGnuMalloc("%a[ab%c] %d", 3, F, C, I);
+ testScanfNoGnuMalloc("%a[^ab%c] %d", 3, F, C, I);
+ testScanfNoGnuMalloc("%as", 1, F);
+ testScanfNoGnuMalloc("%aS", 1, F);
+ testScanfNoGnuMalloc("%a13S", 1, F);
+ testScanfNoGnuMalloc("%alS", 1, F);
+
testScanf("%5$d", 0);
testScanf("%md", 0);
testScanf("%m10s", 0);
More information about the llvm-commits
mailing list