[rtems-tools commit] TraceWriterQEMU.cc: Change strncpy to memcpy

Joel Sherrill joel at rtems.org
Mon Sep 27 22:18:18 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    a06f48a6cd5567e6e173f275127dbaa26da7cfcb
Changeset: http://git.rtems.org/rtems-tools/commit/?id=a06f48a6cd5567e6e173f275127dbaa26da7cfcb

Author:    Ryan Long <ryan.long at oarcorp.com>
Date:      Wed Aug 11 13:43:18 2021 -0400

TraceWriterQEMU.cc: Change strncpy to memcpy

CID 1506207: Buffer not null terminated

Closes #4491

---

 tester/covoar/TraceWriterQEMU.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tester/covoar/TraceWriterQEMU.cc b/tester/covoar/TraceWriterQEMU.cc
index 177b77f..0f1ea67 100644
--- a/tester/covoar/TraceWriterQEMU.cc
+++ b/tester/covoar/TraceWriterQEMU.cc
@@ -106,7 +106,9 @@ 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.
+    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;



More information about the vc mailing list