brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 9e1e428 Raw
52 lines · cpp
1// Test crash gives guidance on -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ and2// ASAN_OPTIONS=detect_container_overflow=03// RUN: %clangxx_asan -O %s -o %t4// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s5//6// Test overflow checks can be disabled at runtime with7// ASAN_OPTIONS=detect_container_overflow=08// RUN: %env_asan_opts=detect_container_overflow=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-NOCRASH %s9//10// Illustrate use of -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ flag to suppress11// overflow checks at compile time.12// RUN: %clangxx_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ -O %s -o %t-no-overflow13// RUN: %run %t-no-overflow 2>&1 | FileCheck --check-prefix=CHECK-NOCRASH %s14//15// UNSUPPORTED: true16 17#include <assert.h>18#include <stdio.h>19#include <string.h>20 21// public definition of __sanitizer_annotate_contiguous_container22#include "sanitizer/common_interface_defs.h"23 24static volatile int one = 1;25 26int TestCrash() {27  long t[100];28  t[60] = 0;29#if __has_feature(address_sanitizer)30  __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,31                                            &t[0] + 50);32#endif33  // CHECK-CRASH: AddressSanitizer: container-overflow34  // CHECK-CRASH: ASAN_OPTIONS=detect_container_overflow=035  // CHECK-CRASH: __SANITIZER_DISABLE_CONTAINER_OVERFLOW__36  // CHECK-NOCRASH-NOT: AddressSanitizer: container-overflow37  // CHECK-NOCRASH-NOT: ASAN_OPTIONS=detect_container_overflow=038  // CHECK-NOCRASH-NOT: __SANITIZER_DISABLE_CONTAINER_OVERFLOW__39  return (int)t[60 * one]; // Touches the poisoned memory.40}41 42int main(int argc, char **argv) {43 44  int retval = 0;45 46  retval = TestCrash();47 48  printf("Exiting main\n");49 50  return retval;51}52