summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDjalal Harouni <tixxdz@opendz.org>2014-10-25 13:02:12 +0100
committerDjalal Harouni <tixxdz@opendz.org>2014-10-25 13:02:12 +0100
commitcc736c9c44c406facd6567f085cd7a298c028e2a (patch)
tree01c6d38c3b28a2fd909b04cfa7ec22033f4c4ae9
parentbac48f70a4b8a1daf0ef0297e0cf75fd93ba8eb4 (diff)
downloadkdbus-bus-cc736c9c44c406facd6567f085cd7a298c028e2a.tar.gz
kdbus-bus-cc736c9c44c406facd6567f085cd7a298c028e2a.tar.bz2
kdbus-bus-cc736c9c44c406facd6567f085cd7a298c028e2a.zip
policy: check if name is valid when updating policies
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
-rw-r--r--policy.c5
-rw-r--r--test/test-policy.c16
2 files changed, 21 insertions, 0 deletions
diff --git a/policy.c b/policy.c
index 0fc542c7552..66bce57eb5e 100644
--- 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;
diff --git a/test/test-policy.c b/test/test-policy.c
index 7ca92291289..4eb6e65f96d 100644
--- a/test/test-policy.c
+++ b/test/test-policy.c
@@ -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);