From: Jérémie Galarneau Date: Mon, 4 Aug 2014 18:10:29 +0000 (-0400) Subject: Disallow wildcards in event names except as the last character X-Git-Tag: v2.6.0-rc1~85 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=930a2e995548ba32bfe27d996e306a07f1129b8a;p=lttng-tools.git Disallow wildcards in event names except as the last character Signed-off-by: Jérémie Galarneau Signed-off-by: David Goulet --- diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index e6c30d660..1220e489a 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 044e9eefe..0cc71303a 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 6e283ccb6..55d56e660 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"