From: Chanwoo Choi Date: Fri, 2 Sep 2022 02:57:51 +0000 (+0900) Subject: tools: system-resource-monitor: Fix coverity issue X-Git-Tag: submit/tizen/20220902.032035^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F66%2F280666%2F1;p=platform%2Fcore%2Fapi%2Fresource-monitor.git tools: system-resource-monitor: Fix coverity issue Change-Id: If1b57a0121a43c9ac65cf72038951ef08a0a7298 Signed-off-by: Chanwoo Choi --- diff --git a/tools/system-resource-monitor/system-resource-monitor.c b/tools/system-resource-monitor/system-resource-monitor.c index 97d2bba..bf33d8b 100644 --- a/tools/system-resource-monitor/system-resource-monitor.c +++ b/tools/system-resource-monitor/system-resource-monitor.c @@ -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 */