From 47bc2cc2cd07a953ae136bc6252c616642ad8437 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Sat, 1 Jun 2019 20:52:19 -0700 Subject: [PATCH] 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 --- libtrace/parse-filter.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 */ -- 2.50.1