summaryrefslogtreecommitdiff
path: root/examples/badcode/targets/badcode2.c
blob: 57018041eeda6dfa2c04ae1c5d67eabf3c346229 (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
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>

#define EXPORT   __attribute__((visibility("default")))
#define NOINLINE __attribute__ ((noinline))

EXPORT NOINLINE void crash()
{
  char src[128];
  char dst[2];
  memcpy(src, dst, 8192);
}

EXPORT NOINLINE void func1()
{
  printf("func1\n");
  crash();
}

EXPORT NOINLINE void func2() 
{
  printf("func2\n");
  crash();
}

EXPORT NOINLINE void driver()
{
  srand(time(0));
  sleep(1);
  if (rand() % 2 == 1) func1();
  else func2();
}

int main(int argc, char ** argv)
{
  driver();
  return 0;
}