Re: [PATCH] libtracefs: Fix tracefs_event_enable/disable() to not have open regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 29.06.21 г. 23:40, Steven Rostedt wrote:
From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

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




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux