From: Dongwoo Lee Date: Tue, 30 Aug 2022 06:49:49 +0000 (-0700) Subject: tools: resource-monitor: Fix to use proper loop bound X-Git-Tag: submit/tizen/20220830.081307~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F47%2F280447%2F1;p=platform%2Fcore%2Fsystem%2Fpass.git tools: resource-monitor: Fix to use proper loop bound Change-Id: I06f4561ea5ba3a626b03da5c8b4e7c6212b0bb9b Signed-off-by: Dongwoo Lee --- diff --git a/tools/resource-monitor/resource-monitor.c b/tools/resource-monitor/resource-monitor.c index ec3e073..ab1ae31 100644 --- a/tools/resource-monitor/resource-monitor.c +++ b/tools/resource-monitor/resource-monitor.c @@ -309,7 +309,14 @@ static inline int get_resource_attr_array_value(struct resource_data *res, int i res->mon_id, res->res_id, res->attrs[idx].id, &array, &length); - if (ret < 0 || length < 0) break; + /* + * Since each array item is represented with %2.2f, they + * occupy 4bytes each at least, for instance, x.xx. So, + * if length is larger than BUFF_MAX/4, it will obviously + * be failed to store in 'buf' and there is no need to proceed. + */ + if (ret < 0 || length < 0 || length > (BUFF_MAX / 4)) + break; memset(buf, 0, BUFF_MAX + 1); for (i = 0; i < length; i++) {