From ea3138c02b0371bd25041b54c3598b6b948803f8 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Tue, 13 Feb 2024 10:34:11 +0900 Subject: [PATCH] fix build error about snprintf 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index 3ff0b6f..25e28ce 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -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; + } } } } -- 2.34.1