util: resource: Check validation of resource control id 16/278516/4
authorChanwoo Choi <cw00.choi@samsung.com>
Wed, 20 Jul 2022 03:56:22 +0000 (12:56 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Sun, 7 Aug 2022 20:32:13 +0000 (05:32 +0900)
When uses the wrong resource control id by client, crash happen
because the invalid array index is used. In order to prevent crash
issue, check the validation of resource control id.

Change-Id: I621757bb17b054dafb246ceac57d3eabf419fc31
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/util/resource.c

index a6fc0b8..52cb8c1 100644 (file)
@@ -263,7 +263,7 @@ int set_resource_control(struct resource *resource, u_int64_t ctrl_id, const voi
        int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
        int ret;
 
-       if (!resource) {
+       if (!resource || ctrl_index < 0 || ctrl_index >= resource->num_ctrls) {
                _E("Invalid parameter\n");
                return -EINVAL;
        }
@@ -284,8 +284,11 @@ const char *get_resource_control_name(struct resource *resource, u_int64_t ctrl_
        const struct resource_control *ctrl;
        int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
 
-       if (!resource)
+       if (!resource || ctrl_index < 0 || ctrl_index >= resource->num_ctrls) {
+               _E("Invalid parameter\n");
                return NULL;
+       }
+
        ctrl = &resource->ctrls[ctrl_index];
 
        return ctrl->name;