about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2023-02-23 21:51:45 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2023-03-17 22:38:16 +0000
commitdd492f8763f13312c17eb67af33e3e90217a30e1 (patch)
treed1d1bf7ffdf3f890a5d5c3c5b6b7214bf60da845
parent71dc423262a91c012d708afc8b2e3cc3abdf49c3 (diff)
downloadklee-dd492f8763f13312c17eb67af33e3e90217a30e1.tar.gz
[MemSan] Mark memory objects modified by syscalls as initialised
-rw-r--r--tools/klee-replay/file-creator.c15
-rw-r--r--tools/ktest-gen/ktest-gen.cpp16
-rw-r--r--tools/ktest-randgen/ktest-randgen.cpp5
3 files changed, 35 insertions, 1 deletions
diff --git a/tools/klee-replay/file-creator.c b/tools/klee-replay/file-creator.c
index 497cf1c3..e103a39f 100644
--- a/tools/klee-replay/file-creator.c
+++ b/tools/klee-replay/file-creator.c
@@ -463,16 +463,31 @@ static void check_file(int index, exe_disk_file_t *dfile) {
   switch (index) {
   case __STDIN:
     strcpy(name, "stdin");
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+    memset(&s, 0, sizeof(struct stat));
+#endif
+#endif
     res = fstat(0, &s);
     break;
   case __STDOUT:
     strcpy(name, "stdout");
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+    memset(&s, 0, sizeof(struct stat));
+#endif
+#endif
     res = fstat(1, &s);
     break;
   default:
     name[0] = 'A' + index;
     name[1] = '\0';
     snprintf(fullname, sizeof(fullname), "%s/%s", replay_dir, name);
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+    memset(&s, 0, sizeof(struct stat));
+#endif
+#endif
     res = stat(fullname, &s);
 
     break;
diff --git a/tools/ktest-gen/ktest-gen.cpp b/tools/ktest-gen/ktest-gen.cpp
index a9f4be7c..331ff7b1 100644
--- a/tools/ktest-gen/ktest-gen.cpp
+++ b/tools/ktest-gen/ktest-gen.cpp
@@ -151,6 +151,11 @@ int main(int argc, char *argv[]) {
          current_file++) {
       char *content_filename = content_filenames_list[current_file];
 
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+      memset(&file_stat[current_file], 0, sizeof(struct stat64));
+#endif
+#endif
       if ((fp[current_file] = fopen(content_filename, "r")) == NULL ||
           stat64(content_filename, file_stat + current_file) < 0) {
         perror("Failed to open");
@@ -218,7 +223,11 @@ int main(int argc, char *argv[]) {
     struct stat64 file_stat;
     char filename[6] = "stdin";
     char statname[11] = "stdin-stat";
-
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+    memset(&file_stat, 0, sizeof(struct stat64));
+#endif
+#endif
     if ((fp = fopen(stdin_content_filename, "r")) == NULL ||
         stat64(stdin_content_filename, &file_stat) < 0) {
       fprintf(stderr, "Failure opening %s\n", stdin_content_filename);
@@ -258,6 +267,11 @@ int main(int argc, char *argv[]) {
     char filename[7] = "stdout";
     char statname[12] = "stdout-stat";
 
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+    memset(&file_stat, 0, sizeof(struct stat64));
+#endif
+#endif
     if ((fp = fopen(stdout_content_filename, "r")) == NULL ||
         stat64(stdout_content_filename, &file_stat) < 0) {
       fprintf(stderr, "Failure opening %s\n", stdout_content_filename);
diff --git a/tools/ktest-randgen/ktest-randgen.cpp b/tools/ktest-randgen/ktest-randgen.cpp
index 04cf53e6..9b7260eb 100644
--- a/tools/ktest-randgen/ktest-randgen.cpp
+++ b/tools/ktest-randgen/ktest-randgen.cpp
@@ -117,6 +117,11 @@ void create_stat(size_t size, struct stat *s) {
     free(filename);
     error_exit("%s:%d: Error writing %s\n", __FILE__, __LINE__, filename);
   }
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+  memset(s, 0, sizeof(struct stat));
+#endif
+#endif
 
   fstat(fd, s);