diff mbox series

libtraceevent: Do not print zero length dynamic strings

Message ID 20210615225520.517fe891@rorschach.local.home (mailing list archive)
State Accepted
Commit 5f33f0a1df8ee5c91f2df5bd6c8f35572829476e
Headers show
Series libtraceevent: Do not print zero length dynamic strings | expand

Commit Message

Steven Rostedt June 16, 2021, 2:55 a.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

If a dynamic string happens to not have any length, which means that it
does not even have a null pointer, but the parsing code will still look at
the offset, and read the string at that location. If there's another
dynamic string after it, it will mistakenly report that next string as the
current one. This can be confusing, as the string being printed is not the
string expected.

Discovered this when playing with kprobes and exec arguments.

Fixes: ("tools/events: Add files to create libtraceevent.a")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/event-parse.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index 1217491..7a75e9b 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -4392,6 +4392,7 @@  static void print_str_arg(struct trace_seq *s, void *data, int size,
 		break;
 	case TEP_PRINT_STRING: {
 		int str_offset;
+		int len;
 
 		if (arg->string.offset == -1) {
 			struct tep_format_field *f;
@@ -4400,6 +4401,10 @@  static void print_str_arg(struct trace_seq *s, void *data, int size,
 			arg->string.offset = f->offset;
 		}
 		str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset));
+		len = (str_offset >> 16) & 0xffff;
+		/* Do not attempt to save zero length dynamic strings */
+		if (!len)
+			break;
 		str_offset &= 0xffff;
 		print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
 		break;