Fix: sessiond: ust-registry: dereference of NULL pointer on allocation failure
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.c
index a8db79ea637d8dea53aced4240cd0aac5496ff44..1b1e65eba1327f06e90344020e490784363ec694 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
@@ -232,9 +222,20 @@ int validate_event_field(struct ustctl_field *field,
        case ustctl_atype_sequence:
        case ustctl_atype_string:
        case ustctl_atype_variant:
+       case ustctl_atype_array_nestable:
+       case ustctl_atype_sequence_nestable:
+       case ustctl_atype_enum_nestable:
+       case ustctl_atype_variant_nestable:
                break;
        case ustctl_atype_struct:
-               if (field->type.u._struct.nr_fields != 0) {
+               if (field->type.u.legacy._struct.nr_fields != 0) {
+                       WARN("Unsupported non-empty struct field.");
+                       ret = -EINVAL;
+                       goto end;
+               }
+               break;
+       case ustctl_atype_struct_nestable:
+               if (field->type.u.struct_nestable.nr_fields != 0) {
                        WARN("Unsupported non-empty struct field.");
                        ret = -EINVAL;
                        goto end;
@@ -242,12 +243,12 @@ int validate_event_field(struct ustctl_field *field,
                break;
 
        case ustctl_atype_float:
-               switch (field->type.u.basic._float.mant_dig) {
+               switch (field->type.u._float.mant_dig) {
                case 0:
                        WARN("UST application '%s' (pid: %d) has unknown float mantissa '%u' "
                                "in field '%s', rejecting event '%s'",
                                app->name, app->pid,
-                               field->type.u.basic._float.mant_dig,
+                               field->type.u._float.mant_dig,
                                field->name,
                                event_name);
                        ret = -EINVAL;
@@ -549,8 +550,8 @@ static void destroy_enum_rcu(struct rcu_head *head)
  * Lookup enumeration by name and comparing enumeration entries.
  * Needs to be called from RCU read-side critical section.
  */
-struct ust_registry_enum *
-       ust_registry_lookup_enum(struct ust_registry_session *session,
+static struct ust_registry_enum *ust_registry_lookup_enum(
+               struct ust_registry_session *session,
                const struct ust_registry_enum *reg_enum_lookup)
 {
        struct ust_registry_enum *reg_enum = NULL;
@@ -681,7 +682,7 @@ end:
  * the enumeration.
  * This MUST be called within a RCU read side lock section.
  */
-void ust_registry_destroy_enum(struct ust_registry_session *reg_session,
+static void ust_registry_destroy_enum(struct ust_registry_session *reg_session,
                struct ust_registry_enum *reg_enum)
 {
        int ret;
@@ -738,13 +739,16 @@ static void destroy_channel(struct ust_registry_channel *chan, bool notif)
                }
        }
 
-       rcu_read_lock();
-       /* Destroy all event associated with this registry. */
-       cds_lfht_for_each_entry(chan->ht->ht, &iter.iter, event, node.node) {
-               /* Delete the node from the ht and free it. */
-               ust_registry_destroy_event(chan, event);
+       if (chan->ht) {
+               rcu_read_lock();
+               /* Destroy all event associated with this registry. */
+               cds_lfht_for_each_entry(
+                               chan->ht->ht, &iter.iter, event, node.node) {
+                       /* Delete the node from the ht and free it. */
+                       ust_registry_destroy_event(chan, event);
+               }
+               rcu_read_unlock();
        }
-       rcu_read_unlock();
        call_rcu(&chan->rcu_head, destroy_channel_rcu);
 }
 
@@ -880,7 +884,9 @@ int ust_registry_session_init(struct ust_registry_session **sessionp,
                const char *root_shm_path,
                const char *shm_path,
                uid_t euid,
-               gid_t egid)
+               gid_t egid,
+               uint64_t tracing_id,
+               uid_t tracing_uid)
 {
        int ret;
        struct ust_registry_session *session;
@@ -962,6 +968,9 @@ int ust_registry_session_init(struct ust_registry_session **sessionp,
                goto error;
        }
 
+       session->tracing_id = tracing_id;
+       session->tracing_uid = tracing_uid;
+
        pthread_mutex_lock(&session->lock);
        ret = ust_metadata_session_statedump(session, app, major, minor);
        pthread_mutex_unlock(&session->lock);
@@ -1031,7 +1040,8 @@ void ust_registry_session_destroy(struct ust_registry_session *reg)
                 * Try deleting the directory hierarchy.
                 */
                (void) run_as_rmdir_recursive(reg->root_shm_path,
-                               reg->uid, reg->gid);
+                               reg->uid, reg->gid,
+                               LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
        }
        /* Destroy the enum hash table */
        if (reg->enums) {
This page took 0.026203 seconds and 4 git commands to generate.