tools: resource-monitor: Use strncat() instead of strcat() 31/280231/2
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 25 Aug 2022 05:30:01 +0000 (14:30 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 30 Aug 2022 00:32:13 +0000 (09:32 +0900)
Change-Id: I24ed13b38bdec088d2230b473033ef4888802893
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
tools/resource-monitor/resource-monitor.c

index ff7a9a4..90dfce9 100644 (file)
@@ -297,8 +297,8 @@ static inline int get_resource_attr_array_value(struct resource_data *res, int i
        int ret = 0;
        int length;
        double *array = NULL;
-       char buf[BUFF_MAX];
-       char temp[10];
+       char buf[BUFF_MAX + 1];
+       char temp[BUFF_MAX];
 
        if (!res)
                return -1;
@@ -311,10 +311,13 @@ static inline int get_resource_attr_array_value(struct resource_data *res, int i
 
                if (ret < 0) break;
 
-               memset(buf, 0, BUFF_MAX);
+               memset(buf, 0, BUFF_MAX + 1);
                for (i = 0; i < length; i++) {
-                       snprintf(temp, 10, "%2.2f ", array[i]);
-                       strcat(buf, temp);
+                       snprintf(temp, BUFF_MAX, "%2.2f ", array[i]);
+                       if (strlen(buf) + strlen(temp) >= BUFF_MAX)
+                               break;
+
+                       strncat(buf, temp, BUFF_MAX);
                }
 
                printf("%40s | %-5s | %s", buf, res->attrs[idx].unit, res->attrs[idx].desc);