linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] libtraceevent: Do not print zero length dynamic strings
Date: Tue, 15 Jun 2021 22:55:20 -0400	[thread overview]
Message-ID: <20210615225520.517fe891@rorschach.local.home> (raw)

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 --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;
-- 
2.29.2


                 reply	other threads:[~2021-06-16  2:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210615225520.517fe891@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).