Fix normalize_path's handling of "/.."

Currently it normalizes the path to a string with a single uninitialized
byte. It should instead normalize it to "/".

Bug: none
Test: /data/nativetest/linker-unit-tests/linker-unit-tests32
Test: /data/nativetest64/linker-unit-tests/linker-unit-tests64
Change-Id: I06e0f7598d16acfa21875dad53efbc293cfeb44d
This commit is contained in:
Ryan Prichard 2018-10-04 14:45:55 -07:00
parent 0adf09b370
commit 269bb496c5
2 changed files with 5 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);