Fix: validate that session, host and basepath are legal
[lttng-tools.git] / src / bin / lttng-relayd / session.c
index 1359e9f4b455833e58b74ace6be4e45f616dc48c..de059aae203e2df17054f9bd1d415279e0bd23bf 100644 (file)
@@ -39,7 +39,7 @@ static int session_set_anonymous_chunk(struct relay_session *session)
        struct lttng_trace_chunk *chunk = NULL;
        enum lttng_trace_chunk_status status;
        struct lttng_directory_handle output_directory;
-       char *base_path = opt_output_path;
+       const char *base_path = opt_output_path;
 
        if (base_path == NULL) {
                /* No output path defined */
@@ -87,7 +87,7 @@ end:
  * Return allocated session or else NULL.
  */
 struct relay_session *session_create(const char *session_name,
-               const char *hostname,
+               const char *hostname, const char *base_path,
                uint32_t live_timer,
                bool snapshot,
                const lttng_uuid sessiond_uuid,
@@ -98,7 +98,23 @@ struct relay_session *session_create(const char *session_name,
                uint32_t minor)
 {
        int ret;
-       struct relay_session *session;
+       struct relay_session *session = NULL;
+
+       if (session_name && strstr(session_name, ".")) {
+               ERR("Illegal character in session name: \"%s\"",
+                               session_name);
+               goto error;
+       }
+       if (base_path && strstr(base_path, "../")) {
+               ERR("Invalid session base path walks up the path hierarchy: \"%s\"",
+                               base_path);
+               goto error;
+       }
+       if (hostname && strstr(hostname, ".")) {
+               ERR("Invalid character in hostname: \"%s\"",
+                               hostname);
+               goto error;
+       }
 
        session = zmalloc(sizeof(*session));
        if (!session) {
@@ -115,6 +131,12 @@ struct relay_session *session_create(const char *session_name,
                WARN("Hostname exceeds maximal allowed length");
                goto error;
        }
+       if (lttng_strncpy(session->base_path, base_path,
+                       sizeof(session->base_path))) {
+               WARN("Base path exceeds maximal allowed length");
+               goto error;
+       }
+
        session->ctf_traces_ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
        if (!session->ctf_traces_ht) {
                goto error;
This page took 0.023895 seconds and 4 git commands to generate.