From: Chanwoo Choi Date: Wed, 20 Jul 2022 03:56:22 +0000 (+0900) Subject: util: resource: Check validation of resource control id X-Git-Tag: submit/tizen/20220809.025855~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F16%2F278516%2F4;p=platform%2Fcore%2Fsystem%2Fpass.git util: resource: Check validation of resource control id 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 --- diff --git a/src/util/resource.c b/src/util/resource.c index a6fc0b8..52cb8c1 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -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;