From dbeab5ee24c669578765783a1a8f00af7b2b52a5 Mon Sep 17 00:00:00 2001 From: Cristian Cadar Date: Wed, 14 Oct 2020 14:56:52 +0100 Subject: Added fortified versions for the functions in the klee-libc library --- runtime/klee-libc/CMakeLists.txt | 3 ++- runtime/klee-libc/fortify-klibc.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 runtime/klee-libc/fortify-klibc.c (limited to 'runtime') diff --git a/runtime/klee-libc/CMakeLists.txt b/runtime/klee-libc/CMakeLists.txt index 653ebb5a..bd23ba93 100644 --- a/runtime/klee-libc/CMakeLists.txt +++ b/runtime/klee-libc/CMakeLists.txt @@ -15,6 +15,7 @@ set(SRC_FILES atoi.c bcmp.c calloc.c + fortify-klibc.c htonl.c memchr.c mempcpy.c @@ -46,4 +47,4 @@ set(ADDITIONAL_CC_FLAGS include("${CMAKE_SOURCE_DIR}/cmake/compile_bitcode_library.cmake") prefix_with_path("${SRC_FILES}" "${CMAKE_CURRENT_SOURCE_DIR}/" prefixed_files) -add_bitcode_library_targets("${LIB_PREFIX}" "${prefixed_files}" "${ADDITIONAL_CC_FLAGS}" "") \ No newline at end of file +add_bitcode_library_targets("${LIB_PREFIX}" "${prefixed_files}" "${ADDITIONAL_CC_FLAGS}" "") diff --git a/runtime/klee-libc/fortify-klibc.c b/runtime/klee-libc/fortify-klibc.c new file mode 100644 index 00000000..ed4a3033 --- /dev/null +++ b/runtime/klee-libc/fortify-klibc.c @@ -0,0 +1,37 @@ +//===-- fortify-klibc.c ---------------------------------------------------===// +// +// The KLEE Symbolic Virtual Machine +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +/* Fortified versions of the libc functions defined in the klee-libc library */ + +#include "klee/klee.h" + +#include + +void *__mempcpy_chk(void *dest, const void *src, size_t len, size_t destlen) { + if (len > destlen) + klee_report_error(__FILE__, __LINE__, "mempcpy overflow", "ptr.err"); + + return mempcpy(dest, src, len); +} + +char *__stpcpy_chk(char *dest, const char *src, size_t destlen) { + return stpcpy(dest, src); +} + +char *__strcat_chk(char *dest, const char *src, size_t destlen) { + return strcat(dest, src); +} + +char *__strcpy_chk(char *dest, const char *src, size_t destlen) { + return strcpy(dest, src); +} + +char *__strncpy_chk(char *s1, const char *s2, size_t n, size_t s1len) { + return strncpy(s1, s2, n); +} -- cgit 1.4.1