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: Fail to parse if sizeof(long) is used and long size is not defined
Date: Wed, 14 Dec 2022 09:36:49 -0500	[thread overview]
Message-ID: <20221214093649.5a8e43af@gandalf.local.home> (raw)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the tep handle has not defined a long size yet, then fail to parse
sizeof(long) instead of giving a wrong answer.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/event-parse.c        | 11 +++++++++--
 utest/traceevent-utest.c |  8 ++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/event-parse.c b/src/event-parse.c
index aaa06b336efe..65937675a67f 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -3544,10 +3544,17 @@ process_sizeof(struct tep_event *event, struct tep_print_arg *arg, char **tok)
 		if (token && strcmp(token, "long") == 0) {
 			arg->atom.atom = strdup("8");
 		} else {
-			if (event->tep->long_size == 4)
+			switch (event->tep->long_size) {
+			case 4:
 				arg->atom.atom = strdup("4");
-			else
+				break;
+			case 8:
 				arg->atom.atom = strdup("8");
+				break;
+			default:
+				/* long size not defined yet, fail to parse it */
+				goto error;
+			}
 			/* The token is the next token */
 			ok = true;
 		}
diff --git a/utest/traceevent-utest.c b/utest/traceevent-utest.c
index 954a592d5c3c..ebd5eb93efc2 100644
--- a/utest/traceevent-utest.c
+++ b/utest/traceevent-utest.c
@@ -140,6 +140,7 @@ static char cpumask_##name##_event_data[] = {                       \
 }
 #endif
 
+#define SIZEOF_LONG0_FMT "[FAILED TO PARSE] s4=0 u4=0 s8=0 u8=0x0"
 #define SIZEOF_LONG4_FMT "int=4 unsigned=4 unsigned int=4 long=4 unsigned long=4 long long=8 unsigned long long=8 s4=4 u4=4 s8=8 u8=8"
 #define SIZEOF_LONG8_FMT "int=4 unsigned=4 unsigned int=4 long=8 unsigned long=8 long long=8 unsigned long long=8 s4=4 u4=4 s8=8 u8=8"
 
@@ -372,6 +373,11 @@ static void test_parse_sizeof4(void)
 	test_parse_sizeof(4, 4, "sizeof4", SIZEOF_LONG4_FMT);
 }
 
+static void test_parse_sizeof_undef(void)
+{
+	test_parse_sizeof(0, 5, "sizeof_undef", SIZEOF_LONG0_FMT);
+}
+
 static int test_suite_destroy(void)
 {
 	tep_free(test_tep);
@@ -418,4 +424,6 @@ void test_traceevent_lib(void)
 		    test_parse_sizeof8);
 	CU_add_test(suite, "parse sizeof() 4byte values",
 		    test_parse_sizeof4);
+	CU_add_test(suite, "parse sizeof() no long size defined",
+		    test_parse_sizeof_undef);
 }
-- 
2.35.1


                 reply	other threads:[~2022-12-14 14:36 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=20221214093649.5a8e43af@gandalf.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).