about summary refs log tree commit diff homepage
path: root/runtime/Freestanding
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/Freestanding')
-rw-r--r--runtime/Freestanding/CMakeLists.txt3
-rw-r--r--runtime/Freestanding/fortify-fs.c36
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);
+}