Disallow wildcards in event names except as the last character
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 4 Aug 2014 18:10:29 +0000 (14:10 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 5 Aug 2014 15:44:22 +0000 (11:44 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/cmd.c
src/common/error.c

index e6c30d6604c491034a65fb5ba35aa4794782108c..1220e489a1b70d5815c9d5ea39e08e994eb0d8b6 100644 (file)
@@ -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 */
index 044e9eefec7e14eab9eb1046411395d1ccdebdff..0cc71303aeb6704de4bc926f39d0e2acbf58bc39 100644 (file)
@@ -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) {
index 6e283ccb6635be96e85b6b7bb2d60653a7ed8d19..55d56e6602d72c9da3527111f43bf58c4f0d2d9b 100644 (file)
@@ -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"
This page took 0.029833 seconds and 5 git commands to generate.