From: Djalal Harouni Date: Sat, 25 Oct 2014 12:02:12 +0000 (+0100) Subject: policy: check if name is valid when updating policies X-Git-Tag: upstream/0.20141102.012929utc~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc736c9c44c406facd6567f085cd7a298c028e2a;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git policy: check if name is valid when updating policies Signed-off-by: Djalal Harouni --- diff --git a/policy.c b/policy.c index 0fc542c..66bce57 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 7ca9229..4eb6e65 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);