Message ID | 20210629164046.48f8b323@oasis.local.home (mailing list archive) |
---|---|
State | Accepted |
Commit | de8592c0ef0b6ed8cedf19e8d0f21858b7d98f38 |
Headers | show |
Series | libtracefs: Fix tracefs_event_enable/disable() to not have open regex | expand |
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); >
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
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);