[lttng-dev] [PATCH lttng-tools] Disallow wildcards in event names except as the last character

Jérémie Galarneau jeremie.galarneau at efficios.com
Mon Aug 4 14:10:29 EDT 2014


Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
---
 include/lttng/lttng-error.h  |  1 +
 src/bin/lttng-sessiond/cmd.c | 37 +++++++++++++++++++++++++++++++++++++
 src/common/error.c           |  1 +
 3 files changed, 39 insertions(+)

diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h
index e6c30d6..1220e48 100644
--- a/include/lttng/lttng-error.h
+++ b/include/lttng/lttng-error.h
@@ -132,6 +132,7 @@ enum lttng_error_code {
 	LTTNG_ERR_NO_CONSUMER            = 109, /* No consumer exist for the session */
 	LTTNG_ERR_EXCLUSION_INVAL        = 110, /* Invalid event exclusion data */
 	LTTNG_ERR_EXCLUSION_NOMEM        = 111, /* Lack of memory while processing event exclusions */
+	LTTNG_ERR_INVALID_EVENT_NAME     = 112, /* Invalid event name */
 
 	/* MUST be last element */
 	LTTNG_ERR_NR,                           /* Last element */
diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
index 044e9ee..0cc7130 100644
--- a/src/bin/lttng-sessiond/cmd.c
+++ b/src/bin/lttng-sessiond/cmd.c
@@ -1301,6 +1301,38 @@ error:
 	return ret;
 }
 
+static int validate_event_name(const char *name)
+{
+	int ret = 0;
+	const char *c = name;
+	const char *event_name_end = c + LTTNG_SYMBOL_NAME_LEN;
+
+	/*
+	 * Make sure that unescaped wildcards are only used as the last
+	 * character of the event name.
+	 */
+	while (c < event_name_end) {
+		switch (*c) {
+		case '\0':
+			goto end;
+		case '\\':
+			c++;
+			break;
+		case '*':
+			if ((c + 1) < event_name_end && *(c + 1)) {
+				/* Wildcard is not the last character */
+				ret = LTTNG_ERR_INVALID_EVENT_NAME;
+				goto end;
+			}
+		default:
+			break;
+		}
+		c++;
+	}
+end:
+	return ret;
+}
+
 /*
  * Command LTTNG_ENABLE_EVENT processed by the client thread.
  */
@@ -1318,6 +1350,11 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
 	assert(event);
 	assert(channel_name);
 
+	ret = validate_event_name(event->name);
+	if (ret) {
+		goto error;
+	}
+
 	rcu_read_lock();
 
 	switch (domain->type) {
diff --git a/src/common/error.c b/src/common/error.c
index 6e283cc..55d56e6 100644
--- a/src/common/error.c
+++ b/src/common/error.c
@@ -164,6 +164,7 @@ static const char *error_string_array[] = {
 	[ ERROR_INDEX(LTTNG_ERR_MI_OUTPUT_TYPE) ] = "Invalid MI output format",
 	[ ERROR_INDEX(LTTNG_ERR_MI_IO_FAIL) ] = "IO error while writing MI output",
 	[ ERROR_INDEX(LTTNG_ERR_MI_NOT_IMPLEMENTED) ] = "Mi feature not implemented",
+	[ ERROR_INDEX(LTTNG_ERR_INVALID_EVENT_NAME) ] = "Invalid event name",
 
 	/* Last element */
 	[ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
-- 
2.0.3




More information about the lttng-dev mailing list