From 5993358225c96b43fb44bb4abdcdddf140f72a30 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 29 Aug 2022 23:49:49 -0700 Subject: [PATCH] tools: resource-monitor: Fix to use proper loop bound Change-Id: I06f4561ea5ba3a626b03da5c8b4e7c6212b0bb9b Signed-off-by: Dongwoo Lee --- tools/resource-monitor/resource-monitor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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++) { -- 2.34.1