linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	"linux-trace-devel@vger.kernel.org" 
	<linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex
Date: Fri, 2 Jul 2021 14:17:52 +0300	[thread overview]
Message-ID: <48ad3a02-f4bf-1579-df6a-f4dc206a7e4e@gmail.com> (raw)
In-Reply-To: <20210629164046.48f8b323@oasis.local.home>



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

  reply	other threads:[~2021-07-02 11:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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) [this message]
2021-07-02 11:36   ` 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=48ad3a02-f4bf-1579-df6a-f4dc206a7e4e@gmail.com \
    --to=y.karadz@gmail.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).