[PATCH] TraceWriterQEMU.cc: Change strncpy to memcpy

Gedare Bloom gedare at rtems.org
Wed Sep 1 20:20:35 UTC 2021


On Thu, Aug 19, 2021 at 7:42 AM Ryan Long <ryan.long at oarcorp.com> wrote:
>
> 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) );

Just to clarify, the header.magic should not be NULL terminated?

If so, then this is fine, but I don't think the temporary local
variable is needed though.
memcpy( header.magic, QEMU_TRACE_MAGIC, sizeof(header.magic) );
should work fine.

>      header.version = QEMU_TRACE_VERSION;
>      header.kind    = QEMU_TRACE_KIND_RAW;  // XXX ??
>      header.sizeof_target_pc = 32;
> --
> 1.8.3.1
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list