about summary refs log tree commit diff homepage
path: root/tools/klee-replay/klee-replay.c
diff options
context:
space:
mode:
authorTimotej Kapus <tk1713@ic.ac.uk>2019-10-24 14:49:07 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2019-10-29 15:39:34 -0400
commit2b78a26d9dbeb7823c5a3487bfa2535fb4b274bf (patch)
tree9104e037c87e7f40ea597dadaed59e3c609e2a01 /tools/klee-replay/klee-replay.c
parent238a7875a94643dc73e5743adb418e497efb85f7 (diff)
downloadklee-2b78a26d9dbeb7823c5a3487bfa2535fb4b274bf.tar.gz
[klee-replay] Fix relative executable paths
Diffstat (limited to 'tools/klee-replay/klee-replay.c')
-rw-r--r--tools/klee-replay/klee-replay.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/tools/klee-replay/klee-replay.c b/tools/klee-replay/klee-replay.c
index 1d35079f..efc101b3 100644
--- a/tools/klee-replay/klee-replay.c
+++ b/tools/klee-replay/klee-replay.c
@@ -321,10 +321,17 @@ int main(int argc, char** argv) {
     }
   }
 
+  // Executable needs to be converted to an absolute path, as klee-replay calls
+  // chdir just before executing it
+  char executable[PATH_MAX];
+  if (!realpath(argv[optind], executable)) {
+    snprintf(executable, PATH_MAX, "KLEE-REPLAY: ERROR: executable %s:",
+             argv[optind]);
+    perror(executable);
+    exit(1);
+  }
   /* Normal execution path ... */
 
-  char* executable = argv[optind];
-
   /* make sure this process has the CAP_SYS_CHROOT capability, if possible. */
 #ifdef HAVE_SYS_CAPABILITY_H
   if (rootdir)
@@ -337,14 +344,6 @@ int main(int argc, char** argv) {
     exit(1);
   }
 
-  /* Verify the executable exists. */
-  FILE *f = fopen(executable, "r");
-  if (!f) {
-    fprintf(stderr, "KLEE-REPLAY: ERROR: executable %s not found.\n", executable);
-    exit(1);
-  }
-  fclose(f);
-
   int idx = 0;
   for (idx = optind + 1; idx != argc; ++idx) {
     char* input_fname = argv[idx];