From 6b4661a7582f6d8bfbba1f8df4a791232bf299ab Mon Sep 17 00:00:00 2001 From: Steffen Schulz Date: Mon, 20 Sep 2021 09:32:18 +0000 Subject: [PATCH] dump_file hypercall: support mkstemps() template with suffix --- nyx/hypercall/hypercall.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nyx/hypercall/hypercall.c b/nyx/hypercall/hypercall.c index 23b584f75b..ef63ddfbd4 100644 --- a/nyx/hypercall/hypercall.c +++ b/nyx/hypercall/hypercall.c @@ -749,12 +749,13 @@ static void handle_hypercall_kafl_dump_file(struct kvm_run *run, CPUState *cpu, assert(asprintf(&host_path, "%s/dump/%s", GET_GLOBAL_STATE()->workdir_path , base_name) != -1); // check if base_name is mkstemp() pattern, otherwise write/append to exact name - if (strlen(base_name) > 6 && 0 == strcmp(base_name+strlen(base_name)-6, "XXXXXX")) { + char *pattern = strstr(base_name, "XXXXXX"); + if (pattern) { + unsigned suffix = strlen(pattern) - strlen("XXXXXX"); + f = fdopen(mkstemps(host_path, suffix), "w+"); if (file_obj.append) { - fprintf(stderr, "Error request to append but no filename given in %s\n", __func__); - goto err_out1; + fprintf(stderr, "Warning in %s: Writing unique generated file in append mode?\n", __func__); } - f = fdopen(mkstemp(host_path), "w+"); } else { if (file_obj.append){ f = fopen(host_path, "a+");