fix build error about snprintf 99/305899/2
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 13 Feb 2024 01:34:11 +0000 (10:34 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Wed, 14 Feb 2024 09:00:36 +0000 (18:00 +0900)
The output may be truncated before the last format character. So, it checked length before using snprintf

Change-Id: Iad722db28a5fd443df33988adbb4b755aa5afaa3

common/vc_info_parser.c

index 3ff0b6f..25e28ce 100644 (file)
@@ -378,10 +378,12 @@ static int __is_symbolic_link(const char* path, bool* is_symbolic)
                        char current_working_directory[PATH_MAX];
                        char temp_path[PATH_MAX];
                        if (getcwd(current_working_directory, PATH_MAX)) {
-                               snprintf(temp_path, PATH_MAX, "%s/%s", current_working_directory, path);
-                               if (strncmp(temp_path, real_path, strlen(temp_path) + 1) == 0) {
-                                       SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] %s is real file, not symbolic link", path);
-                                       *is_symbolic = false;
+                               if (strlen(current_working_directory) + strlen(path) <= PATH_MAX) {
+                                       snprintf(temp_path, PATH_MAX, "%s/%s", current_working_directory, path);
+                                       if (strncmp(temp_path, real_path, strlen(temp_path) + 1) == 0) {
+                                               SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] %s is real file, not symbolic link", path);
+                                               *is_symbolic = false;
+                                       }
                                }
                        }
                }