[v2,3/4] trace: fix metadata dump
diff mbox series

Message ID 20201028210249.9021-4-david.marchand@redhat.com
State Accepted, archived
Delegated to: David Marchand
Headers show
Series
  • Rework CTF event description storage
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand Oct. 28, 2020, 9:02 p.m. UTC
The ctf metadata is written to the metadata file without any check for
length, so this string must be null terminated.

Fixes: f1a099f5b1f1 ("trace: create CTF TDSL metadata in memory")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_trace_ctf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Sunil Kumar Kori Oct. 29, 2020, 8:36 a.m. UTC | #1
>-----Original Message-----
>From: David Marchand <david.marchand@redhat.com>
>Sent: Thursday, October 29, 2020 2:33 AM
>To: dev@dpdk.org
>Cc: Jerin Jacob Kollanukkaran <jerinj@marvell.com>; Sunil Kumar Kori
><skori@marvell.com>
>Subject: [EXT] [PATCH v2 3/4] trace: fix metadata dump
>
>External Email
>
>----------------------------------------------------------------------
>The ctf metadata is written to the metadata file without any check for length,
>so this string must be null terminated.
>
>Fixes: f1a099f5b1f1 ("trace: create CTF TDSL metadata in memory")
>
>Signed-off-by: David Marchand <david.marchand@redhat.com>
>---
> lib/librte_eal/common/eal_common_trace_ctf.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c
>b/lib/librte_eal/common/eal_common_trace_ctf.c
>index ac1f64d04b..22615c4e73 100644
>--- a/lib/librte_eal/common/eal_common_trace_ctf.c
>+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
>@@ -37,11 +37,12 @@ meta_copy(char **meta, int *offset, char *str, int rc)
> 	if (rc < 0)
> 		return rc;
>
>-	ptr = realloc(ptr, count + rc);
>+	ptr = realloc(ptr, count + rc + 1);
> 	if (ptr == NULL)
> 		goto free_str;
>
> 	memcpy(RTE_PTR_ADD(ptr, count), str, rc);
>+	ptr[count + rc] = '\0';
> 	count += rc;
> 	free(str);
>
>--
>2.23.0
Acked-by: Sunil Kumar Kori <skori@mavell.com>

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index ac1f64d04b..22615c4e73 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -37,11 +37,12 @@  meta_copy(char **meta, int *offset, char *str, int rc)
 	if (rc < 0)
 		return rc;
 
-	ptr = realloc(ptr, count + rc);
+	ptr = realloc(ptr, count + rc + 1);
 	if (ptr == NULL)
 		goto free_str;
 
 	memcpy(RTE_PTR_ADD(ptr, count), str, rc);
+	ptr[count + rc] = '\0';
 	count += rc;
 	free(str);