Add a return value check routine 21/308221/1 accepted/tizen/unified/20240325.141227 accepted/tizen/unified/x/20240320.133000
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 19 Mar 2024 11:42:44 +0000 (20:42 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Wed, 20 Mar 2024 02:10:15 +0000 (11:10 +0900)
Change-Id: I8dbf71575f71e18fbfa2417c58d67ad4c73fe6e0

common/vc_info_parser.c

index 3eb3081..e07601d 100644 (file)
@@ -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;
                                        }