From: Dongwoo Lee Date: Thu, 25 Aug 2022 05:30:01 +0000 (+0900) Subject: tools: resource-monitor: Use strncat() instead of strcat() X-Git-Tag: submit/tizen/20220830.030501~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff38f3e0c117e9e55f12e01e89c52f6dfd2c7682;p=platform%2Fcore%2Fsystem%2Fpass.git tools: resource-monitor: Use strncat() instead of strcat() Change-Id: I24ed13b38bdec088d2230b473033ef4888802893 Signed-off-by: Dongwoo Lee Signed-off-by: Chanwoo Choi --- diff --git a/tools/resource-monitor/resource-monitor.c b/tools/resource-monitor/resource-monitor.c index ff7a9a4..90dfce9 100644 --- a/tools/resource-monitor/resource-monitor.c +++ b/tools/resource-monitor/resource-monitor.c @@ -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);