From 552fb6af769715e5045b23ba4af9be2d698ff8ef Mon Sep 17 00:00:00 2001 From: Cristian Cadar Date: Fri, 6 Nov 2020 16:47:47 +0000 Subject: Added fortified versions for the functions in the freestanding library. --- runtime/Freestanding/CMakeLists.txt | 3 ++- runtime/Freestanding/fortify-fs.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 runtime/Freestanding/fortify-fs.c (limited to 'runtime') 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 + +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); +} -- cgit 1.4.1