tools: system-resource-monitor: Fix coverity issue 66/280666/1 accepted/tizen/unified/20220904.214051 submit/tizen/20220902.032035 submit/tizen/20220902.091829
authorChanwoo Choi <cw00.choi@samsung.com>
Fri, 2 Sep 2022 02:57:51 +0000 (11:57 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 2 Sep 2022 02:57:51 +0000 (11:57 +0900)
Change-Id: If1b57a0121a43c9ac65cf72038951ef08a0a7298
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
tools/system-resource-monitor/system-resource-monitor.c

index 97d2bbaed541a521a7b9e84976c59e08b2c0224e..bf33d8b94d50f514bac60dd4198c101d64d9e20a 100644 (file)
@@ -273,7 +273,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) 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++) {
@@ -431,6 +438,8 @@ static int system_resource_monitor_init(void)
 
        /* 1. Initialize resource-monitor */
        id = resource_monitor_init();
+       if (id < 0)
+               return id;
        g_data.mon_id = id;
 
        /* 2. Get resource count */