linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jerome Marchand" <jmarchan@redhat.com>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Jerome Marchand <jmarchan@redhat.com>
Subject: [PATCH 4/4] libtraceevent: don't return a pointer to a local variable get_field_str()
Date: Fri,  7 Jun 2024 18:05:42 +0200	[thread overview]
Message-ID: <20240607160542.46152-5-jmarchan@redhat.com> (raw)
In-Reply-To: <20240607160542.46152-1-jmarchan@redhat.com>

The function get_field_str() can return a pointer to string on the
stack. Replace it by a global variable.

Fixes a RETURN_LOCAL error (CWE-562)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 src/parse-filter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/parse-filter.c b/src/parse-filter.c
index e448ee2..f0c0ae1 100644
--- a/src/parse-filter.c
+++ b/src/parse-filter.c
@@ -1698,6 +1698,8 @@ static int test_num(struct tep_event *event, struct tep_filter_arg *arg,
 	}
 }
 
+char hex[64];
+
 static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record *record)
 {
 	struct tep_event *event;
@@ -1705,7 +1707,6 @@ static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record *
 	unsigned long long addr;
 	const char *val = NULL;
 	unsigned int size;
-	char hex[64];
 
 	/* If the field is not a string convert it */
 	if (arg->str.field->flags & TEP_FIELD_IS_STRING) {
-- 
2.45.1


  parent reply	other threads:[~2024-06-07 16:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07 16:05 [PATCH 0/4] libtraceevent: fix misc issues found by static analysis Jerome Marchand
2024-06-07 16:05 ` [PATCH 1/4] libtraceevent: close shared object in the error path of load_plugin() Jerome Marchand
2024-06-07 16:05 ` [PATCH 2/4] libtraceevent: prevent a memory leak in process_fields() Jerome Marchand
2024-06-07 16:05 ` [PATCH 3/4] libtraceevent: prevent a memory leak in tep_plugin_add_option() Jerome Marchand
2024-06-07 16:05 ` Jerome Marchand [this message]
2024-06-14 19:49   ` [PATCH 4/4] libtraceevent: don't return a pointer to a local variable get_field_str() Steven Rostedt

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=20240607160542.46152-5-jmarchan@redhat.com \
    --to=jmarchan@redhat.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.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).