From f4dfcd7641a91b7d02e1dd01613ce6095c4c837f Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 19 Mar 2024 20:42:44 +0900 Subject: [PATCH] Add a return value check routine Change-Id: I8dbf71575f71e18fbfa2417c58d67ad4c73fe6e0 --- common/vc_info_parser.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index 3eb3081..e07601d 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -375,12 +375,15 @@ static int __is_symbolic_link(const char* path, bool* is_symbolic) SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] %s is real file, not symbolic link", path); *is_symbolic = false; } else { - char current_working_directory[PATH_MAX]; - char temp_path[PATH_MAX*2]; + char current_working_directory[PATH_MAX + 1] = {'\0', }; + char temp_path[PATH_MAX + 1] = {'\0', }; if (getcwd(current_working_directory, PATH_MAX)) { - if (strlen(current_working_directory) + strlen(path) <= PATH_MAX*2) { - snprintf(temp_path, PATH_MAX*2, "%s/%s", current_working_directory, path); - if (strncmp(temp_path, real_path, strlen(temp_path) + 1) == 0) { + if (strlen(current_working_directory) + strlen(path) < PATH_MAX) { + int ret = snprintf(temp_path, PATH_MAX, "%s/%s", current_working_directory, path); + if (ret < 0) { + SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Error occurred while concatenating paths : %s %s", + current_working_directory, path); + } else 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