diff options
author | Cristian Cadar <c.cadar@imperial.ac.uk> | 2020-11-06 16:47:47 +0000 |
---|---|---|
committer | MartinNowack <2443641+MartinNowack@users.noreply.github.com> | 2020-11-09 19:39:13 +0000 |
commit | 552fb6af769715e5045b23ba4af9be2d698ff8ef (patch) | |
tree | a9a9342379afac54992054c1d038a7ac1c264af5 | |
parent | d28c99001b6b0690195a16de13239441178e2abf (diff) | |
download | klee-552fb6af769715e5045b23ba4af9be2d698ff8ef.tar.gz |
Added fortified versions for the functions in the freestanding library.
-rw-r--r-- | runtime/Freestanding/CMakeLists.txt | 3 | ||||
-rw-r--r-- | runtime/Freestanding/fortify-fs.c | 36 |
2 files changed, 38 insertions, 1 deletions
diff --git a/runtime/Freestanding/CMakeLists.txt b/runtime/Freestanding/CMakeLists.txt index 872a4f05..43f1afc7 100644 --- a/runtime/Freestanding/CMakeLists.txt +++ b/runtime/Freestanding/CMakeLists.txt @@ -9,6 +9,7 @@ set(LIB_PREFIX "RuntimeFreestanding") set(SRC_FILES + fortify-fs.c memcmp.c memcpy.c memmove.c @@ -18,4 +19,4 @@ set(SRC_FILES # Build it 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}" "" "") \ No newline at end of file +add_bitcode_library_targets("${LIB_PREFIX}" "${prefixed_files}" "" "") diff --git a/runtime/Freestanding/fortify-fs.c b/runtime/Freestanding/fortify-fs.c new file mode 100644 index 00000000..3bbd34df --- /dev/null +++ b/runtime/Freestanding/fortify-fs.c @@ -0,0 +1,36 @@ +//===-- fortify-fs.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 FreeStanding library + */ + +#include "klee/klee.h" + +#include <string.h> + +void *__memmove_chk(void *dest, const void *src, size_t len, size_t destlen) { + if (len > destlen) + klee_report_error(__FILE__, __LINE__, "memmove overflow", "ptr.err"); + + return memmove(dest, src, len); +} + +void *__memset_chk(void *dest, int c, size_t len, size_t destlen) { + if (len > destlen) + klee_report_error(__FILE__, __LINE__, "memset overflow", "ptr.err"); + + return memset(dest, c, len); +} + +void *__memcpy_chk(void *dest, const void *src, size_t len, size_t destlen) { + if (len > destlen) + klee_report_error(__FILE__, __LINE__, "memcpy overflow", "ptr.err"); + + return memcpy(dest, src, len); +} |