From: Steven Rostedt <rostedt@goodmis.org>
To: "Jerome Marchand" <jmarchan@redhat.com>
Cc: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH 4/4] libtraceevent: don't return a pointer to a local variable get_field_str()
Date: Fri, 14 Jun 2024 15:49:16 -0400 [thread overview]
Message-ID: <20240614154916.6e63bd2d@rorschach.local.home> (raw)
In-Reply-To: <20240607160542.46152-5-jmarchan@redhat.com>
On Fri, 7 Jun 2024 18:05:42 +0200
"Jerome Marchand" <jmarchan@redhat.com> wrote:
> 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];
Instead of making hex a global variable (which is incorrect for
multiple reasons, and can caus bugs elsewhere). Just make it a static
variable here.
static char hex[64];
I'll fix this and give you a reported-by.
-- Steve
>
> /* If the field is not a string convert it */
> if (arg->str.field->flags & TEP_FIELD_IS_STRING) {
prev parent reply other threads:[~2024-06-14 19:49 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 ` [PATCH 4/4] libtraceevent: don't return a pointer to a local variable get_field_str() Jerome Marchand
2024-06-14 19:49 ` Steven Rostedt [this message]
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=20240614154916.6e63bd2d@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=jmarchan@redhat.com \
--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).