mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-12 01:20:14 +00:00
tracing: Check for printable characters when printing field dyn strings
When the "fields" option is enabled, it prints each trace event field based on its type. But a dynamic array and a dynamic string can both have a "char *" type. Printing it as a string can cause escape characters to be printed and mess up the output of the trace. For dynamic strings, test if there are any non-printable characters, and if so, print both the string with the non printable characters as '.', and the print the hex value of the array. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Takaya Saeki <takayas@google.com> Cc: Tom Zanussi <zanussi@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ian Rogers <irogers@google.com> Cc: Douglas Raillard <douglas.raillard@arm.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ingo Molnar <mingo@redhat.com> Link: https://lore.kernel.org/20251028231148.929243047@kernel.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
This commit is contained in:
parent
64b627c8da
commit
b6e5d971fc
@ -950,7 +950,9 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
|
||||
int offset;
|
||||
int len;
|
||||
int ret;
|
||||
int i;
|
||||
void *pos;
|
||||
char *str;
|
||||
|
||||
list_for_each_entry_reverse(field, head, link) {
|
||||
trace_seq_printf(&iter->seq, " %s=", field->name);
|
||||
@ -977,8 +979,29 @@ static void print_fields(struct trace_iterator *iter, struct trace_event_call *c
|
||||
trace_seq_puts(&iter->seq, "<OVERFLOW>");
|
||||
break;
|
||||
}
|
||||
pos = (void *)iter->ent + offset;
|
||||
trace_seq_printf(&iter->seq, "%.*s", len, (char *)pos);
|
||||
str = (char *)iter->ent + offset;
|
||||
/* Check if there's any non printable strings */
|
||||
for (i = 0; i < len; i++) {
|
||||
if (str[i] && !(isascii(str[i]) && isprint(str[i])))
|
||||
break;
|
||||
}
|
||||
if (i < len) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (isascii(str[i]) && isprint(str[i]))
|
||||
trace_seq_putc(&iter->seq, str[i]);
|
||||
else
|
||||
trace_seq_putc(&iter->seq, '.');
|
||||
}
|
||||
trace_seq_puts(&iter->seq, " (");
|
||||
for (i = 0; i < len; i++) {
|
||||
if (i)
|
||||
trace_seq_putc(&iter->seq, ':');
|
||||
trace_seq_printf(&iter->seq, "%02x", str[i]);
|
||||
}
|
||||
trace_seq_putc(&iter->seq, ')');
|
||||
} else {
|
||||
trace_seq_printf(&iter->seq, "%.*s", len, str);
|
||||
}
|
||||
break;
|
||||
case FILTER_PTR_STRING:
|
||||
if (!iter->fmt_size)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user