about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--include/common.h2
-rw-r--r--src/afl-common.c24
2 files changed, 18 insertions, 8 deletions
diff --git a/include/common.h b/include/common.h
index 279a5f47..e03566de 100644
--- a/include/common.h
+++ b/include/common.h
@@ -150,7 +150,7 @@ void *afl_memmem(const void *haystack, size_t haystacklen, const void *needle,
 #ifdef __linux__
 /* Nyx helper functions to create and remove tmp workdirs */
 char* create_nyx_tmp_workdir(void);
-void remove_nyx_tmp_workdir(char* nyx_out_dir_path);
+void remove_nyx_tmp_workdir(afl_forkserver_t *fsrv, char* nyx_out_dir_path);
 #endif
 
 #endif
diff --git a/src/afl-common.c b/src/afl-common.c
index 7dbf7129..fe0db94d 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -1381,12 +1381,22 @@ char* create_nyx_tmp_workdir(void) {
 }
 
 /* Vice versa, we remove the tmp workdir for nyx with this helper function. */
-void remove_nyx_tmp_workdir(char* nyx_out_dir_path) {
-  /* Fix me: This is not recursive, so it will always fail. Use a libnyx helper function instead
-   * to remove the workdir safely (and not risking to wipe the whole filesystem accidentally). */
-  //if (rmdir(nyx_out_dir_path)) { 
-  //  PFATAL("Unable to remove nyx workdir"); 
-  //}
-  free(nyx_out_dir_path);
+void remove_nyx_tmp_workdir(afl_forkserver_t *fsrv, char* nyx_out_dir_path) {
+  char* workdir_path = alloc_printf("%s/workdir", nyx_out_dir_path);
+
+  if (access(workdir_path, R_OK) == 0) {
+    if(fsrv->nyx_handlers->nyx_remove_work_dir(workdir_path) != true) {
+      WARNF("Unable to remove nyx workdir (%s)", workdir_path);
+    }
+  }
+
+  if (access(nyx_out_dir_path, R_OK) == 0) {
+    if (rmdir(nyx_out_dir_path)) {
+      WARNF("Unable to remove nyx workdir (%s)", nyx_out_dir_path);
+    }
+  }
+
+  ck_free(workdir_path);
+  ck_free(nyx_out_dir_path);
 }
 #endif