about summary refs log tree commit diff homepage
path: root/test/Runtime/klee-libc/strcat_chk.c
blob: 58b806ce4cbd4ab91d5b761337279968c93e76d8 (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
// This test checks that __strcat_chk is properly handled when klee-libc is used

// RUN: %clang %s -emit-llvm -O2 -g -c -D_FORTIFY_SOURCE=1 -o %t2.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --libc=klee --exit-on-error %t2.bc

// RUN: %clang %s -emit-llvm -O2 -g -c -D_FORTIFY_SOURCE=2 -o %t3.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --libc=klee --exit-on-error %t3.bc

#include "klee/klee.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>

int main() {
#define N 7
  int i;
  char *s = malloc(N);
  klee_make_symbolic(s, N, "s");
  s[N - 1] = '\0';

  char *d = malloc(N + 4);
  d[0] = 'a';
  d[1] = 'b';
  d[2] = 'c';
  d[3] = '\0';
  strcat(d, s);

  assert(!strcmp(s, d + 3));
}