Walter Lee 00b4931d5d [asan] Port tests to shadow scale of 5
The tests are ported as follows:

contiguous_container_crash.cc
use-after-delete.cc
use-after-free.cc
  Replace hardwired shadow granularity in CHECK statements with regex.

max_redzone.cc
  Bump max_redzone parameter to 32.

memset_test.cc
  Bump size parameter of __asan_poison_memory_region to 32.

scariness_score_test.cc
  For "far-from-bounds" heap overflow, make sure overflow is more than
  one shadow granularity away.

  At large shadow granularity, there is not enough redzone between
  stack elements to detect far-from-bounds, so fake out that test.

Differential Revision: https://reviews.llvm.org/D39773

llvm-svn: 318470
2017-11-16 23:28:50 +00:00

72 lines
2.8 KiB
C++

// Test that large memset/memcpy/memmove check the entire range.
// RUN: %clangxx_asan -O0 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O1 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O2 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O3 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O0 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O1 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O2 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O3 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O0 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O1 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O2 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O3 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O2 -DTEST_MEMCPY_SIZE_OVERFLOW %s -o %t && not %run %t 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-MEMCPY_SIZE_OVERFLOW
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sanitizer/asan_interface.h>
typedef void *(*memcpy_t)(void *, const void *, size_t);
int main(int argc, char **argv) {
char * volatile p = (char *)malloc(3000);
__asan_poison_memory_region(p + 512, 32);
#if defined(TEST_MEMSET)
memset(p, 0, 3000);
assert(p[1] == 0);
// CHECK-MEMSET: AddressSanitizer: use-after-poison on address
// CHECK-MEMSET: in {{.*}}memset
#else
char * volatile q = (char *)malloc(3000);
#if defined(TEST_MEMCPY)
memcpy(q, p, 3000);
// CHECK-MEMCPY: AddressSanitizer: use-after-poison on address
// On Mac, memmove and memcpy are the same. Accept either one.
// CHECK-MEMCPY: in {{.*(memmove|memcpy)}}
#elif defined(TEST_MEMMOVE)
memmove(q, p, 3000);
// CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address
// CHECK-MEMMOVE: in {{.*(memmove|memcpy)}}
#elif defined(TEST_MEMCPY_SIZE_OVERFLOW)
volatile memcpy_t my_memcpy = &memcpy;
my_memcpy(p, q, -argc);
// CHECK-MEMCPY_SIZE_OVERFLOW: AddressSanitizer: negative-size-param: (size=-1)
#endif
assert(q[1] == 0);
free(q);
#endif
free(p);
return 0;
}