32 lines · c
1// Test strict_string_checks option in strstr function2// RUN: %clang_asan %s -o %t && %run %t 2>&13 4// Newer versions of Android's strstr() uses memchr() internally, which actually5// does trigger a heap-buffer-overflow (as it tries to find the6// null-terminator). The same applies to FreeBSD.7// UNSUPPORTED: android, target={{.*freebsd.*}}8// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&19 10// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s11 12#include <assert.h>13#include <stdlib.h>14#include <string.h>15 16int main(int argc, char **argv) {17 size_t size = 100;18 char fill = 'o';19 char *s1 = (char*)malloc(size);20 char *s2 = (char*)malloc(size);21 memset(s1, fill, size);22 memset(s2, fill, size);23 s2[size - 1]='\0';24 char* r = strstr(s1, s2);25 // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}26 // CHECK: READ of size {{101|100}}27 assert(r == s1);28 free(s1);29 free(s2);30 return 0;31}32