about summary refs log tree commit diff
path: root/test/test-compcov.c
blob: f1743265cb7dd2ba69038d29ac89512d1159ba1f (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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

char global_cmpval[] = "GLOBALVARIABLE";

int main(int argc, char **argv) {

  char *input = argv[1], *buf, buffer[20];
  char  cmpval[] = "LOCALVARIABLE";
  char  shortval[4] = "abc";

  if (argc < 2) {

    ssize_t ret = read(0, buffer, sizeof(buffer) - 1);
    buffer[ret] = 0;
    input = buffer;

  }

  if (strcmp(input, "LIBTOKENCAP") == 0)
    printf("your string was libtokencap\n");
  else if (strcmp(input, "BUGMENOT") == 0)
    printf("your string was bugmenot\n");
  else if (strcmp(input, "BUFFEROVERFLOW") == 0) {

    buf = malloc(16);
    strcpy(buf, "TEST");
    strcat(buf, input);
    printf("This will only crash with libdislocator: %s\n", buf);
    return 0;

  } else if (*(unsigned int *)input == 0xabadcafe)

    printf("GG you eat cmp tokens for breakfast!\n");
  else if (memcmp(cmpval, input, 8) == 0)
    printf("local var memcmp works!\n");
  else if (memcmp(shortval, input, 4) == 0)
    printf("short local var memcmp works!\n");
  else if (memcmp(global_cmpval, input, sizeof(global_cmpval)) == 0)
    printf("global var memcmp works!\n");
  else
    printf("I do not know your string\n");

  return 0;

}