[dpdk-dev] [PATCH 0/3] Rework CTF event description storage

David Marchand david.marchand at redhat.com
Wed Oct 28 16:17:43 CET 2020


On Wed, Oct 28, 2020 at 2:09 PM David Marchand
<david.marchand at redhat.com> wrote:
> > echo "trace_autotest" |  ./build/app/test/dpdk-test  -c 0x3 --trace=.*
> > --no-huge --trace=.*
>
> Err, indeed, thanks for catching.
> I did some diff on metadata files, but did not notice this trailing character.
>
> This is an issue with the metadata string manipulations, that appears
> with the last patch...
> I ended up rewriting most of _ctf.c (removing intermediate buffers
> allocations) and it works but I'll see if I can pinpoint the issue.

The problem is in the current HEAD, but it is revealed by my series,
maybe because the dynamicity around allocations changed.
I see no check on the length of trace->ctf_meta when writing to the
metadata file.
Did I miss something?


int
rte_trace_metadata_dump(FILE *f)
{
...
        rc = fprintf(f, "%s", ctf_meta);
...
}


Breakpoint 1, trace_mkdir () at
../lib/librte_eal/common/eal_common_trace_utils.c:317
317    {
(gdb) p strlen(trace_obj_get()->ctf_meta)
$2 = 21865
(gdb) p trace_obj_get()->ctf_meta[21865]
$3 = 0 '\000'
(gdb) set trace_obj_get()->ctf_meta[21865] = 'A'
...

$ babeltrace $(ls -1rtd $HOME/dpdk-traces/* |tail -1)
[error] at line 1008: token "A": syntax error, unexpected IDENTIFIER
[error] Error creating AST
...


This fixes it:
@@ -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);


-- 
David Marchand



More information about the dev mailing list