diff --git a/linker/linker_utils.cpp b/linker/linker_utils.cpp index 789d5c1b8..6b9aec9fa 100644 --- a/linker/linker_utils.cpp +++ b/linker/linker_utils.cpp @@ -98,8 +98,8 @@ bool normalize_path(const char* path, std::string* normalized_path) { while (out_ptr > buf && *--out_ptr != '/') { } if (in_ptr[0] == 0) { - // retain '/' - out_ptr++; + // retain '/' (or write the initial '/' for "/..") + *out_ptr++ = '/'; } continue; } diff --git a/linker/tests/linker_utils_test.cpp b/linker/tests/linker_utils_test.cpp index dce223a10..e406af5f6 100644 --- a/linker/tests/linker_utils_test.cpp +++ b/linker/tests/linker_utils_test.cpp @@ -58,6 +58,9 @@ TEST(linker_utils, normalize_path_smoke) { ASSERT_TRUE(normalize_path("/a/../../b", &output)); ASSERT_EQ("/b", output); + ASSERT_TRUE(normalize_path("/..", &output)); + ASSERT_EQ("/", output); + output = "unchanged"; ASSERT_FALSE(normalize_path("root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output)); ASSERT_EQ("unchanged", output);