aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/asan/strlen-overflow-1.c
blob: 4833dc77891ecf46c6ccec04f8e692240da18cba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* { dg-do run } */
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
/* { dg-shouldfail "asan" } */

#include <stdbool.h>
#include <sanitizer/asan_interface.h>

char a[2] = "0";

#ifdef __cplusplus
extern "C"
#endif

__attribute__((no_sanitize_address, noinline)) __SIZE_TYPE__
strlen (const char *p) {

  __SIZE_TYPE__ n = 0;
  for (; *p; ++n, ++p);
  return n;
}

int main () {
  char *p = &a[0];
  asm ("" : "+r"(p));
  __asan_poison_memory_region ((char *)&a[1], 1);
  return __builtin_strlen (a);
}

/* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
/* { dg-output "    #0 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*strlen-overflow-1.c:26|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */