summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2022-07-20 12:56:22 +0900
committerChanwoo Choi <cw00.choi@samsung.com>2022-08-08 05:32:13 +0900
commite7976a043eb67e73b885a3d5a9a8df15bfa447f7 (patch)
tree8ab16d8a8f70040f027dc2b51b98b9a47edfa12e
parent3e2a6f1dc62fc03d818d9024e129abf82a0dceb6 (diff)
downloadpass-e7976a043eb67e73b885a3d5a9a8df15bfa447f7.tar.gz
pass-e7976a043eb67e73b885a3d5a9a8df15bfa447f7.tar.bz2
pass-e7976a043eb67e73b885a3d5a9a8df15bfa447f7.zip
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 <cw00.choi@samsung.com>
-rw-r--r--src/util/resource.c7
1 files 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;