linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Ian Rogers <irogers@google.com>
Cc: linux-trace-devel@vger.kernel.org,
	Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Subject: Re: [PATCH 3/3] libtracefs: Move initialization below a null test.
Date: Thu, 24 Feb 2022 18:55:56 -0500	[thread overview]
Message-ID: <20220224185556.2771ad18@gandalf.local.home> (raw)
In-Reply-To: <20220224234823.1190425-3-irogers@google.com>

On Thu, 24 Feb 2022 15:48:23 -0800
Ian Rogers <irogers@google.com> wrote:

> Computing the address from a NULL pointer results in undefined behavior
> which things like undefined behavior sanitizer promote into real
> failures.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  src/tracefs-dynevents.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
> index 61804b9..8fee474 100644
> --- a/src/tracefs-dynevents.c
> +++ b/src/tracefs-dynevents.c
> @@ -724,13 +724,18 @@ tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
>  		      char **event, char **prefix, char **addr, char **format)
>  {
>  	char **lv[] = { system, event, prefix, addr, format };
> -	char **rv[] = { &dynevent->system, &dynevent->event, &dynevent->prefix,
> -			&dynevent->address, &dynevent->format };
> +	char **rv[] = { NULL, NULL, NULL, NULL, NULL };
>  	int i;

I don't really like the NULL initialization done like this.

What about just adding a helper function. That is.

diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
index 61804b9d9d5e..48bb26a96c58 100644
--- a/src/tracefs-dynevents.c
+++ b/src/tracefs-dynevents.c
@@ -704,24 +704,9 @@ __hidden int dynevent_get_count(unsigned int types, const char *system)
 	return all;
 }
 
-/**
- * tracefs_dynevent_info - return details of a dynamic event
- * @dynevent: A dynamic event context, describing given dynamic event.
- * @group: return, group in which the dynamic event is configured
- * @event: return, name of the dynamic event
- * @prefix: return, prefix string of the dynamic event
- * @addr: return, the function and offset (or address) of the dynamic event
- * @format: return, the format string of the dynamic event
- *
- * Returns the type of the dynamic event, or TRACEFS_DYNEVENT_UNKNOWN in case of an error.
- * Any of the @group, @event, @prefix, @addr and @format parameters are optional.
- * If a valid pointer is passed, in case of success - a string is allocated and returned.
- * These strings must be freed with free().
- */
-
-enum tracefs_dynevent_type
-tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
-		      char **event, char **prefix, char **addr, char **format)
+static enum tracefs_dynevent_type
+dynevent_info(struct tracefs_dynevent *dynevent, char **system,
+	      char **event, char **prefix, char **addr, char **format)
 {
 	char **lv[] = { system, event, prefix, addr, format };
 	char **rv[] = { &dynevent->system, &dynevent->event, &dynevent->prefix,
@@ -754,6 +739,30 @@ error:
 	return TRACEFS_DYNEVENT_UNKNOWN;
 }
 
+/**
+ * tracefs_dynevent_info - return details of a dynamic event
+ * @dynevent: A dynamic event context, describing given dynamic event.
+ * @group: return, group in which the dynamic event is configured
+ * @event: return, name of the dynamic event
+ * @prefix: return, prefix string of the dynamic event
+ * @addr: return, the function and offset (or address) of the dynamic event
+ * @format: return, the format string of the dynamic event
+ *
+ * Returns the type of the dynamic event, or TRACEFS_DYNEVENT_UNKNOWN in case of an error.
+ * Any of the @group, @event, @prefix, @addr and @format parameters are optional.
+ * If a valid pointer is passed, in case of success - a string is allocated and returned.
+ * These strings must be freed with free().
+ */
+enum tracefs_dynevent_type
+tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
+		      char **event, char **prefix, char **addr, char **format)
+{
+	if (!dynevent)
+		return TRACEFS_DYNEVENT_UNKNOWN;
+
+	return dynevent_info(dynevent, system, event, prefix, addr, format);
+}
+
 /**
  * tracefs_dynevent_get_event - return tep event representing the given dynamic event
  * @tep: a handle to the trace event parser context that holds the events


-- Steve

  reply	other threads:[~2022-02-24 23:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 23:48 [PATCH 1/3] libtracefs: Fix spelling in test name Ian Rogers
2022-02-24 23:48 ` [PATCH 2/3] libtracefs: Avoid null access Ian Rogers
2022-02-24 23:48 ` [PATCH 3/3] libtracefs: Move initialization below a null test Ian Rogers
2022-02-24 23:55   ` Steven Rostedt [this message]
2022-02-25  0:09     ` Ian Rogers
2022-02-25  0:20       ` Steven Rostedt
2022-02-25  0:21         ` Ian Rogers

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=20220224185556.2771ad18@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=irogers@google.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /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).