about summary refs log tree commit diff homepage
path: root/runtime/POSIX
diff options
context:
space:
mode:
authorFrank Busse <bb0xfb@gmail.com>2022-03-18 09:46:14 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2022-07-07 18:30:34 +0100
commitd2f5906da4ae37a41ae257e5308d50e19689877b (patch)
tree40bb75bc1153dbf37f0df31674cf67e4af3c4da3 /runtime/POSIX
parent99c522b14dbbf6b26be35b6e7bb8da7b29070287 (diff)
downloadklee-d2f5906da4ae37a41ae257e5308d50e19689877b.tar.gz
POSIX runtime: fstatat: check for nonnull path APIs
Diffstat (limited to 'runtime/POSIX')
-rw-r--r--runtime/POSIX/CMakeLists.txt5
-rw-r--r--runtime/POSIX/fd.c15
2 files changed, 15 insertions, 5 deletions
diff --git a/runtime/POSIX/CMakeLists.txt b/runtime/POSIX/CMakeLists.txt
index 02d06736..d8208d9b 100644
--- a/runtime/POSIX/CMakeLists.txt
+++ b/runtime/POSIX/CMakeLists.txt
@@ -20,6 +20,11 @@ set(SRC_FILES
         stubs.c
         )
 
+try_compile (FSTATAT_PATH_ACCEPTS_NULL
+        ${CMAKE_BINARY_DIR}
+        ${PROJECT_SOURCE_DIR}/cmake/fstatat.c
+        )
+
 # Build it
 include("${CMAKE_SOURCE_DIR}/cmake/compile_bitcode_library.cmake")
 prefix_with_path("${SRC_FILES}" "${CMAKE_CURRENT_SOURCE_DIR}/" prefixed_files)
diff --git a/runtime/POSIX/fd.c b/runtime/POSIX/fd.c
index 35d0d315..0aba0ade 100644
--- a/runtime/POSIX/fd.c
+++ b/runtime/POSIX/fd.c
@@ -568,16 +568,21 @@ int fstatat(int fd, const char *path, struct stat *buf, int flags) {
     return 0;
   } 
 
+#ifdef FSTATAT_PATH_ACCEPTS_NULL
+  #define PATHPARAM (path ? __concretize_string(path) : NULL)
+#else
+  assert(path);
+  #define PATHPARAM (__concretize_string(path))
+#endif
+
 #if (defined __NR_newfstatat) && (__NR_newfstatat != 0)
-  return syscall(__NR_newfstatat, (long)fd,
-                 (path ? __concretize_string(path) : NULL), buf, (long)flags);
+  return syscall(__NR_newfstatat, (long)fd, PATHPARAM, buf, (long)flags);
 #else
-  return syscall(__NR_fstatat64, (long)fd,
-                 (path ? __concretize_string(path) : NULL), buf, (long)flags);
+  return syscall(__NR_fstatat64, (long)fd, PATHPARAM, buf, (long)flags);
 #endif
+#undef PATHPARAM
 }
 
-
 int __fd_lstat(const char *path, struct stat64 *buf) {
   exe_disk_file_t *dfile = __get_sym_file(path);
   if (dfile) {