]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
libtrace: Fix get_field_str() for dynamic strings
authorCong Wang <xiyou.wangcong@gmail.com>
Sun, 2 Jun 2019 03:52:19 +0000 (20:52 -0700)
committerCong Wang <xiyou.wangcong@gmail.com>
Sun, 2 Jun 2019 04:00:20 +0000 (21:00 -0700)
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 <xiyou.wangcong@gmail.com>
libtrace/parse-filter.c

index 7e7bf3f39d8147d725e8b5b64e34d8192b4051b4..70913fd906d9dbca1ec87a3758e88a23b8578cd1 100644 (file)
@@ -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 */