From e7976a043eb67e73b885a3d5a9a8df15bfa447f7 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 20 Jul 2022 12:56:22 +0900 Subject: 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 --- src/util/resource.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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; -- cgit v1.2.3