tools: resource-monitor: Fix to use proper loop bound 47/280447/1
authorDongwoo Lee <dwlee08@gmail.com>
Tue, 30 Aug 2022 06:49:49 +0000 (23:49 -0700)
committerDongwoo Lee <dwlee08@gmail.com>
Tue, 30 Aug 2022 07:45:03 +0000 (00:45 -0700)
Change-Id: I06f4561ea5ba3a626b03da5c8b4e7c6212b0bb9b
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
tools/resource-monitor/resource-monitor.c

index ec3e073d1cfc4533c35f9b06ca0e4663e9d75410..ab1ae3152d331127f77a56424846699df2ddcdb6 100644 (file)
@@ -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++) {