From 1132e3d4e4f2fd5e7c58fbf54e792b9f469603ad Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 27 Apr 2023 16:58:53 -0700 Subject: [PATCH] Use NamedTemporaryFile to create a temporary file instead of mktemp --- archr/analyzers/qemu_tracer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/archr/analyzers/qemu_tracer.py b/archr/analyzers/qemu_tracer.py index a27e040..d6057b7 100644 --- a/archr/analyzers/qemu_tracer.py +++ b/archr/analyzers/qemu_tracer.py @@ -236,9 +236,9 @@ def fire_context( r.halfway_core_path = local_halfway_core_filename if target_trace_filename: - temp_trace_file = tempfile.mktemp(dir="/tmp", prefix="tracer-") - self.target.copy_file(target_trace_filename, temp_trace_file) - trace_fh = open(temp_trace_file, "rb") + temp_trace_file = tempfile.NamedTemporaryFile() + self.target.copy_file(target_trace_filename, temp_trace_file.name) + trace_fh = open(temp_trace_file.name, "rb") # Find where qemu loaded the binary. Primarily for PIE try: @@ -296,6 +296,8 @@ def fire_context( lastline = entry bbl_trace_fh.close() + trace_fh.close() + temp_trace_file.close() r.trace = QEMUBBLTrace(bbl_trace_file.name, bbl_trace_len) if r.crashed: