Fix the build error using gcc 13 30/295230/1 accepted/tizen/unified/20230706.152150 accepted/tizen/unified/dev/20230726.115715
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 4 Jul 2023 04:43:08 +0000 (13:43 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 4 Jul 2023 04:43:08 +0000 (13:43 +0900)
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 <sy.kwak@samsung.com>
src/process/proc-main.c

index 42ca970..6881605 100644 (file)
@@ -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);