aboutsummaryrefslogtreecommitdiff
path: root/test/safestack/overflow.c
blob: 14e29823cd9941ced4962f01a38556a9813a5f43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// RUN: %clang_safestack %s -o %t
// RUN: %run %t

// RUN: %clang_nosafestack -fno-stack-protector %s -o %t
// RUN: not %run %t

// Test that buffer overflows on the unsafe stack do not affect variables on the
// safe stack.

__attribute__((noinline))
void fct(volatile int *buffer)
{
  memset(buffer - 1, 0, 7 * sizeof(int));
}

int main(int argc, char **argv)
{
  int value1 = 42;
  int buffer[5];
  int value2 = 42;
  fct(buffer);
  return value1 != 42 || value2 != 42;
}