Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib traceevent: Fix get_field_str() for dynamic strings

If a field is a dynamic string, get_field_str() returned just the
offset/size value and not the string. Have it parse the offset/size
correctly to return the actual string. Otherwise filtering fails when
trying to filter fields that are dynamic strings.

Reported-by: Gopanapalli Pradeep <prap_hai@yahoo.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/20180112004823.146333275@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Steven Rostedt (VMware) and committed by
Arnaldo Carvalho de Melo
d777f8de 806efaed

+9 -1
+9 -1
tools/lib/traceevent/parse-filter.c
··· 1877 1877 struct pevent *pevent; 1878 1878 unsigned long long addr; 1879 1879 const char *val = NULL; 1880 + unsigned int size; 1880 1881 char hex[64]; 1881 1882 1882 1883 /* If the field is not a string convert it */ 1883 1884 if (arg->str.field->flags & FIELD_IS_STRING) { 1884 1885 val = record->data + arg->str.field->offset; 1886 + size = arg->str.field->size; 1887 + 1888 + if (arg->str.field->flags & FIELD_IS_DYNAMIC) { 1889 + addr = *(unsigned int *)val; 1890 + val = record->data + (addr & 0xffff); 1891 + size = addr >> 16; 1892 + } 1885 1893 1886 1894 /* 1887 1895 * We need to copy the data since we can't be sure the field 1888 1896 * is null terminated. 1889 1897 */ 1890 - if (*(val + arg->str.field->size - 1)) { 1898 + if (*(val + size - 1)) { 1891 1899 /* copy it */ 1892 1900 memcpy(arg->str.buffer, val, arg->str.field->size); 1893 1901 /* the buffer is already NULL terminated */