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:
parent
0adf09b370
commit
269bb496c5
|
@ -98,8 +98,8 @@ bool normalize_path(const char* path, std::string* normalized_path) {
|
||||||
while (out_ptr > buf && *--out_ptr != '/') {
|
while (out_ptr > buf && *--out_ptr != '/') {
|
||||||
}
|
}
|
||||||
if (in_ptr[0] == 0) {
|
if (in_ptr[0] == 0) {
|
||||||
// retain '/'
|
// retain '/' (or write the initial '/' for "/..")
|
||||||
out_ptr++;
|
*out_ptr++ = '/';
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,9 @@ TEST(linker_utils, normalize_path_smoke) {
|
||||||
ASSERT_TRUE(normalize_path("/a/../../b", &output));
|
ASSERT_TRUE(normalize_path("/a/../../b", &output));
|
||||||
ASSERT_EQ("/b", output);
|
ASSERT_EQ("/b", output);
|
||||||
|
|
||||||
|
ASSERT_TRUE(normalize_path("/..", &output));
|
||||||
|
ASSERT_EQ("/", output);
|
||||||
|
|
||||||
output = "unchanged";
|
output = "unchanged";
|
||||||
ASSERT_FALSE(normalize_path("root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output));
|
ASSERT_FALSE(normalize_path("root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output));
|
||||||
ASSERT_EQ("unchanged", output);
|
ASSERT_EQ("unchanged", output);
|
||||||
|
|
Loading…
Reference in New Issue