used snprintf instead of strncat 61/305761/2
authordyamy-lee <dyamy.lee@samsung.com>
Wed, 7 Feb 2024 04:56:22 +0000 (13:56 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Wed, 7 Feb 2024 10:53:00 +0000 (19:53 +0900)
Actually, getcwd() returns value when it doesn't have error case like sizeof() <= strlen().
However, using snprintf() looks more safe. So, it was changed.

Change-Id: Id091e366801cc98d80ce3c2281a40d0f954e234f

common/vc_info_parser.c

index 3e7ee27..3ff0b6f 100644 (file)
@@ -375,10 +375,10 @@ 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];
-                       if (getcwd(temp_path, PATH_MAX)) {
-                               strncat(temp_path, "/", sizeof(temp_path) - strlen(temp_path) - 1);
-                               strncat(temp_path, path, sizeof(temp_path) - strlen(temp_path) - 1);
+                       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;