policy: check if name is valid when updating policies
authorDjalal Harouni <tixxdz@opendz.org>
Sat, 25 Oct 2014 12:02:12 +0000 (13:02 +0100)
committerDjalal Harouni <tixxdz@opendz.org>
Sat, 25 Oct 2014 12:02:12 +0000 (13:02 +0100)
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
policy.c
test/test-policy.c

index 0fc542c75521673a44f06a76bb42daf56f7939a2..66bce57eb5e6bee0509086e91bfc249de6f1bc35 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -505,6 +505,11 @@ int kdbus_policy_set(struct kdbus_policy_db *db,
                                goto exit;
                        }
 
+                       if (!kdbus_name_is_valid(item->str, true)) {
+                               ret = -EINVAL;
+                               goto exit;
+                       }
+
                        e = kzalloc(sizeof(*e), GFP_KERNEL);
                        if (!e) {
                                ret = -ENOMEM;
index 7ca922912895bfda4f88b3e47d7c4b8c75a9fd1a..4eb6e65f96d12baf5471e5da6f33b1066f8ba28e 100644 (file)
@@ -18,6 +18,15 @@ int kdbus_test_policy(struct kdbus_test_env *env)
        struct kdbus_policy_access access;
        int ret;
 
+       /* Invalid name */
+       conn_a = kdbus_hello_registrar(env->buspath, ".example.a",
+                                      NULL, 0, KDBUS_HELLO_POLICY_HOLDER);
+       ASSERT_RETURN(conn_a == NULL);
+
+       conn_a = kdbus_hello_registrar(env->buspath, "example",
+                                      NULL, 0, KDBUS_HELLO_POLICY_HOLDER);
+       ASSERT_RETURN(conn_a == NULL);
+
        conn_a = kdbus_hello_registrar(env->buspath, "com.example.a",
                                       NULL, 0, KDBUS_HELLO_POLICY_HOLDER);
        ASSERT_RETURN(conn_a);
@@ -58,6 +67,13 @@ int kdbus_test_policy(struct kdbus_test_env *env)
        ret = kdbus_conn_update_policy(conn_b, "com.example.*", &access, 1);
        ASSERT_RETURN(ret == -EEXIST);
 
+       /* Invalid name */
+       ret = kdbus_conn_update_policy(conn_b, ".example.*", &access, 1);
+       ASSERT_RETURN(ret == -EINVAL);
+
+       ret = kdbus_conn_update_policy(conn_b, "example", &access, 1);
+       ASSERT_RETURN(ret == -EINVAL);
+
        kdbus_conn_free(conn_b);
        kdbus_conn_free(conn_a);