[PATCH] TraceWriterQEMU.cc: Change strncpy to memcpy

Ryan Long ryan.long at oarcorp.com
Thu Aug 19 13:42:27 UTC 2021


CID 1506207: Buffer not null terminated

Closes #4491
---
 tester/covoar/TraceWriterQEMU.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tester/covoar/TraceWriterQEMU.cc b/tester/covoar/TraceWriterQEMU.cc
index c417745..be9b6e1 100644
--- a/tester/covoar/TraceWriterQEMU.cc
+++ b/tester/covoar/TraceWriterQEMU.cc
@@ -106,7 +106,10 @@ namespace Trace {
     //
     //  Write the Header to the file
     //
-    strncpy( header.magic, QEMU_TRACE_MAGIC, sizeof(header.magic) );
+    // The header.magic field is actually 12 bytes, but QEMU_TRACE_MAGIC is
+    // 13 bytes including the NULL.
+    const char qemu_trace_magic[13] = QEMU_TRACE_MAGIC;
+    memcpy( header.magic, qemu_trace_magic, sizeof(header.magic) );
     header.version = QEMU_TRACE_VERSION;
     header.kind    = QEMU_TRACE_KIND_RAW;  // XXX ??
     header.sizeof_target_pc = 32;
-- 
1.8.3.1



More information about the devel mailing list