linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex
@ 2021-06-29 20:40 Steven Rostedt
  2021-07-02 11:17 ` Yordan Karadzhov (VMware)
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2021-06-29 20:40 UTC (permalink / raw)
  To: linux-trace-devel

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

Found that calling tracefs_event_enable/disable() will match all content
of the passed in strings and not just what is passed in.

That is, if you have two events, "open" and "open2", and call

 tracefs_event_enable(NULL, NULL, "open");

it will match both the "open" event as well as the "open2" event. This is
because the regex is open ended.

To fix this, add a '^' to the beginning of the match and a '$' to the end
(if they do not already exist).

Fixes: fc94d1a8 ("libtracefs: Add tracefs_event_enable/disable() API")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/tracefs-events.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 0fef64f..b6d3136 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -828,6 +828,26 @@ static int enable_disable_all(struct tracefs_instance *instance,
 	return ret < 0 ? ret : 0;
 }
 
+static int make_regex(regex_t *re, const char *match)
+{
+	int len = strlen(match);
+	char str[len + 3];
+	char *p = &str[0];
+
+	if (!len || match[0] != '^')
+		*(p++) = '^';
+
+	strcpy(p, match);
+	p += len;
+
+	if (!len || match[len-1] != '$')
+		*(p++) = '$';
+
+	*p = '\0';
+
+	return regcomp(re, str, REG_ICASE|REG_NOSUB);
+}
+
 static int event_enable_disable(struct tracefs_instance *instance,
 				const char *system, const char *event,
 				bool enable)
@@ -847,12 +867,13 @@ static int event_enable_disable(struct tracefs_instance *instance,
 		goto out_free;
 
 	if (system) {
+		ret = make_regex(&system_re, system);
 		ret = regcomp(&system_re, system, REG_ICASE|REG_NOSUB);
 		if (ret < 0)
 			goto out_free;
 	}
 	if (event) {
-		ret = regcomp(&event_re, event, REG_ICASE|REG_NOSUB);
+		ret = make_regex(&event_re, event);
 		if (ret < 0) {
 			if (system)
 				regfree(&system_re);
-- 
2.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex
  2021-06-29 20:40 [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex Steven Rostedt
@ 2021-07-02 11:17 ` Yordan Karadzhov (VMware)
  2021-07-02 11:36   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-07-02 11:17 UTC (permalink / raw)
  To: Steven Rostedt, linux-trace-devel



On 29.06.21 г. 23:40, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> Found that calling tracefs_event_enable/disable() will match all content
> of the passed in strings and not just what is passed in.
> 
> That is, if you have two events, "open" and "open2", and call
> 
>   tracefs_event_enable(NULL, NULL, "open");
> 
> it will match both the "open" event as well as the "open2" event. This is
> because the regex is open ended.
> 
> To fix this, add a '^' to the beginning of the match and a '$' to the end
> (if they do not already exist).
> 
> Fixes: fc94d1a8 ("libtracefs: Add tracefs_event_enable/disable() API")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>   src/tracefs-events.c | 23 ++++++++++++++++++++++-
>   1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/src/tracefs-events.c b/src/tracefs-events.c
> index 0fef64f..b6d3136 100644
> --- a/src/tracefs-events.c
> +++ b/src/tracefs-events.c
> @@ -828,6 +828,26 @@ static int enable_disable_all(struct tracefs_instance *instance,
>   	return ret < 0 ? ret : 0;
>   }
>   
> +static int make_regex(regex_t *re, const char *match)
> +{
> +	int len = strlen(match);
> +	char str[len + 3];
> +	char *p = &str[0];
> +
> +	if (!len || match[0] != '^')
> +		*(p++) = '^';
> +
> +	strcpy(p, match);
> +	p += len;
> +
> +	if (!len || match[len-1] != '$')
> +		*(p++) = '$';
> +
> +	*p = '\0';
> +
> +	return regcomp(re, str, REG_ICASE|REG_NOSUB);
> +}
> +
>   static int event_enable_disable(struct tracefs_instance *instance,
>   				const char *system, const char *event,
>   				bool enable)
> @@ -847,12 +867,13 @@ static int event_enable_disable(struct tracefs_instance *instance,
>   		goto out_free;
>   
>   	if (system) {
> +		ret = make_regex(&system_re, system);
>   		ret = regcomp(&system_re, system, REG_ICASE|REG_NOSUB);

I think we forgot to remove the line above.
Thanks!
Y.

>   		if (ret < 0)
>   			goto out_free;
>   	}
>   	if (event) {
> -		ret = regcomp(&event_re, event, REG_ICASE|REG_NOSUB);
> +		ret = make_regex(&event_re, event);
>   		if (ret < 0) {
>   			if (system)
>   				regfree(&system_re);
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex
  2021-07-02 11:17 ` Yordan Karadzhov (VMware)
@ 2021-07-02 11:36   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-07-02 11:36 UTC (permalink / raw)
  To: Yordan Karadzhov (VMware); +Cc: linux-trace-devel

On Fri, 2 Jul 2021 14:17:52 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> > @@ -847,12 +867,13 @@ static int event_enable_disable(struct tracefs_instance *instance,
> >   		goto out_free;
> >   
> >   	if (system) {
> > +		ret = make_regex(&system_re, system);
> >   		ret = regcomp(&system_re, system, REG_ICASE|REG_NOSUB);  
> 
> I think we forgot to remove the line above.

Yes I did, good catch.

-- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-02 11:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 20:40 [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex Steven Rostedt
2021-07-02 11:17 ` Yordan Karadzhov (VMware)
2021-07-02 11:36   ` Steven Rostedt

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).