From 64a404f89da5aa6a99e688c007c56f1f422541bc Mon Sep 17 00:00:00 2001 From: Luca Dariz Date: Mon, 8 Sep 2014 16:54:21 +0200 Subject: add tests for unsigned integer overflow --- test/Feature/ubsan_add_overflow.c | 19 +++++++++++++++++++ test/Feature/ubsan_mul_overflow.c | 19 +++++++++++++++++++ test/Feature/ubsan_sub_overflow.c | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/Feature/ubsan_add_overflow.c create mode 100644 test/Feature/ubsan_mul_overflow.c create mode 100644 test/Feature/ubsan_sub_overflow.c (limited to 'test/Feature') diff --git a/test/Feature/ubsan_add_overflow.c b/test/Feature/ubsan_add_overflow.c new file mode 100644 index 00000000..87701029 --- /dev/null +++ b/test/Feature/ubsan_add_overflow.c @@ -0,0 +1,19 @@ +// RUN: %llvmgcc %s -fsanitize=unsigned-integer-overflow -emit-llvm -g -O0 -c -o %t.bc +// RUN: %klee %t.bc 2> %t.log +// RUN: grep -c "overflow on unsigned addition" %t.log +// RUN: grep -c "ubsan_add_overflow.c:16: overflow" %t.log + +#include "klee/klee.h" + +int main() +{ + unsigned int x; + unsigned int y; + volatile unsigned int result; + + klee_make_symbolic(&x, sizeof(x), "unsigned add 1"); + klee_make_symbolic(&y, sizeof(y), "unsigned add 2"); + result = x + y; + + return 0; +} diff --git a/test/Feature/ubsan_mul_overflow.c b/test/Feature/ubsan_mul_overflow.c new file mode 100644 index 00000000..bbf6df06 --- /dev/null +++ b/test/Feature/ubsan_mul_overflow.c @@ -0,0 +1,19 @@ +// RUN: %llvmgcc %s -fsanitize=unsigned-integer-overflow -emit-llvm -g -O0 -c -o %t.bc +// RUN: %klee %t.bc 2> %t.log +// RUN: grep -c "overflow on unsigned multiplication" %t.log +// RUN: grep -c "ubsan_mul_overflow.c:16: overflow" %t.log + +#include "klee/klee.h" + +int main() +{ + unsigned int x; + unsigned int y; + volatile unsigned int result; + + klee_make_symbolic(&x, sizeof(x), "unsigned add 1"); + klee_make_symbolic(&y, sizeof(y), "unsigned add 2"); + result = x * y; + + return 0; +} diff --git a/test/Feature/ubsan_sub_overflow.c b/test/Feature/ubsan_sub_overflow.c new file mode 100644 index 00000000..37a251bc --- /dev/null +++ b/test/Feature/ubsan_sub_overflow.c @@ -0,0 +1,19 @@ +// RUN: %llvmgcc %s -fsanitize=unsigned-integer-overflow -emit-llvm -g -O0 -c -o %t.bc +// RUN: %klee %t.bc 2> %t.log +// RUN: grep -c "overflow on unsigned subtraction" %t.log +// RUN: grep -c "ubsan_sub_overflow.c:16: overflow" %t.log + +#include "klee/klee.h" + +int main() +{ + unsigned int x; + unsigned int y; + volatile unsigned int result; + + klee_make_symbolic(&x, sizeof(x), "unsigned add 1"); + klee_make_symbolic(&y, sizeof(y), "unsigned add 2"); + result = x - y; + + return 0; +} -- cgit 1.4.1