names: check if name is valid for CMD_NAME_ACQUIRE and CMD_NAME_RELEASE
authorDjalal Harouni <tixxdz@opendz.org>
Fri, 24 Oct 2014 22:11:49 +0000 (23:11 +0100)
committerDjalal Harouni <tixxdz@opendz.org>
Fri, 24 Oct 2014 22:11:49 +0000 (23:11 +0100)
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
kdbus.txt
names.c

index d5079aa51aaba2595cfeb1de1338d07187040557..846d195561f7fc6ad35890698e53cb669af8183f 100644 (file)
--- a/kdbus.txt
+++ b/kdbus.txt
@@ -1771,7 +1771,7 @@ For KDBUS_CMD_NAME_ACQUIRE:
 
 For KDBUS_CMD_NAME_RELEASE:
 
-  -EINVAL      Invalid command flags provided
+  -EINVAL      Invalid command flags, or invalid name provided
   -ESRCH       Name is not found found in the registry
   -EADDRINUSE  Name is owned by a different connection and can't be released
 
diff --git a/names.c b/names.c
index 02efef39fddbcd105da7e608cab253c636800788..5f8853cbc919273d6bdbc27a549739823250bf64 100644 (file)
--- a/names.c
+++ b/names.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2013-2014 Daniel Mack <daniel@zonque.org>
  * Copyright (C) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
  * Copyright (C) 2013-2014 Linux Foundation
+ * Copyright (C) 2014 Djalal Harouni
  *
  * kdbus is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the
@@ -647,6 +648,9 @@ int kdbus_cmd_name_acquire(struct kdbus_name_registry *reg,
        if (ret < 0)
                return -EINVAL;
 
+       if (!kdbus_name_is_valid(name, false))
+               return -EINVAL;
+
        /*
         * Do atomic_inc_return here to reserve our slot, then decrement
         * it before returning.
@@ -688,6 +692,9 @@ int kdbus_cmd_name_release(struct kdbus_name_registry *reg,
        if (ret < 0)
                return -EINVAL;
 
+       if (!kdbus_name_is_valid(name, false))
+               return -EINVAL;
+
        ret = kdbus_ep_policy_check_see_access(conn->ep, conn, name);
        if (ret < 0)
                return ret;