From: SangYoun Kwak Date: Tue, 4 Jul 2023 04:43:08 +0000 (+0900) Subject: Fix the build error using gcc 13 X-Git-Tag: accepted/tizen/unified/20230706.152150^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ca3154a65554a421e482dfb3ce79e12e5ab0a92;p=platform%2Fcore%2Fsystem%2Fresourced.git Fix the build error using gcc 13 In the function "resourced_proc_dump" from src/process/proc-main.c, it concatenates directory and filename and writes it into a buffer using snprintf. In this situation, the gcc-13 compiler complains about: the length of directory + filename can be greater than the size of the buffer, so it should be handled. It is already handled by checking the lengths of the directory & filename but the compiler don't know about it. To fix this situation, codes for checking the return value of snprintf have been added. Change-Id: I2776c5164c57323212e09377ca0eff1f55279ec6 Signed-off-by: SangYoun Kwak --- diff --git a/src/process/proc-main.c b/src/process/proc-main.c index 42ca970..6881605 100644 --- a/src/process/proc-main.c +++ b/src/process/proc-main.c @@ -1822,6 +1822,7 @@ void resourced_proc_dump(int mode, const char *dirpath) char buf[MAX_PATH_LENGTH]; char filename[MAX_NAME_LENGTH]; int name_len; + int path_len; _cleanup_fclose_ FILE *f = NULL; if (dirpath) { @@ -1842,7 +1843,18 @@ void resourced_proc_dump(int mode, const char *dirpath) return; } - snprintf(buf, MAX_PATH_LENGTH, "%s%s", dirpath, filename); + path_len = snprintf(buf, MAX_PATH_LENGTH, "%s%s", dirpath, filename); + + if (path_len < 0) { + _E("[PROCESS] Failed to write dump path"); + return; + } + + if (MAX_PATH_LENGTH <= path_len) { + _E("[PROCESS] Dump path is too long"); + return; + } + f = fopen(buf, "w+"); } proc_dump_process_list(f);