From: Cong Wang Date: Sun, 2 Jun 2019 03:52:19 +0000 (-0700) Subject: libtrace: Fix get_field_str() for dynamic strings X-Git-Tag: v0.6.3~18^2~1^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=47bc2cc2cd07a953ae136bc6252c616642ad8437;p=users%2Fmchehab%2Frasdaemon.git libtrace: Fix get_field_str() for dynamic strings This cherry-picks the libtraceevent commit d777f8de99b0 ("tools lib traceevent: Fix get_field_str() for dynamic strings") from Linux kernel git repo. Signed-off-by: Cong Wang --- diff --git a/libtrace/parse-filter.c b/libtrace/parse-filter.c index 7e7bf3f..70913fd 100644 --- a/libtrace/parse-filter.c +++ b/libtrace/parse-filter.c @@ -1720,17 +1720,25 @@ static const char *get_field_str(struct filter_arg *arg, struct pevent_record *r struct pevent *pevent; unsigned long long addr; const char *val = NULL; + unsigned int size; char hex[64]; /* If the field is not a string convert it */ if (arg->str.field->flags & FIELD_IS_STRING) { val = record->data + arg->str.field->offset; + size = arg->str.field->size; + + if (arg->str.field->flags & FIELD_IS_DYNAMIC) { + addr = *(unsigned int *)val; + val = record->data + (addr & 0xffff); + size = addr >> 16; + } /* * We need to copy the data since we can't be sure the field * is null terminated. */ - if (*(val + arg->str.field->size - 1)) { + if (*(val + size - 1)) { /* copy it */ memcpy(arg->str.buffer, val, arg->str.field->size); /* the buffer is already NULL terminated */