names: do not allow to add names to dead connections
authorKay Sievers <kay@vrfy.org>
Mon, 24 Mar 2014 02:32:52 +0000 (03:32 +0100)
committerKay Sievers <kay@vrfy.org>
Mon, 24 Mar 2014 02:32:52 +0000 (03:32 +0100)
names.c

diff --git a/names.c b/names.c
index c8aa43e646fc1be80170b3a84b1cb8e4ab883b0b..dc02c344611edb00d1044a1468197c164dbee6cb 100644 (file)
--- a/names.c
+++ b/names.c
@@ -515,8 +515,17 @@ int kdbus_name_acquire(struct kdbus_name_registry *reg,
        e->flags = *flags;
        INIT_LIST_HEAD(&e->queue_list);
        e->name_id = ++reg->name_seq_last;
+
+       mutex_lock(&conn->lock);
+       if (!kdbus_conn_active(conn)) {
+               mutex_unlock(&conn->lock);
+               kfree(e);
+               ret = -ECONNRESET;
+               goto exit_unlock;
+       }
        hash_add(reg->entries_hash, &e->hentry, hash);
        kdbus_name_entry_set_owner(e, conn);
+       mutex_unlock(&conn->lock);
 
        kdbus_notify_name_change(KDBUS_ITEM_NAME_ADD,
                                 0, e->conn->id,