Skip to content

Commit

Permalink
kernelbase: Don't strip leading dots in relative paths.
Browse files Browse the repository at this point in the history
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49315
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
(cherry picked from commit c27b246)
  • Loading branch information
rbernon authored and aeikum committed Jun 18, 2021
1 parent 911926e commit 35803e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dlls/kernelbase/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ BOOL WINAPI PathCanonicalizeW(WCHAR *buffer, const WCHAR *path)
{
src += 2; /* Skip .\ */
}
else if (src[1] == '.' && (dst == buffer || dst[-1] == '\\'))
else if (src[1] == '.' && dst != buffer && dst[-1] == '\\')
{
/* \.. backs up a directory, over the root if it has no \ following X:.
* .. is ignored if it would remove a UNC server name or initial \\
Expand Down
25 changes: 25 additions & 0 deletions dlls/shlwapi/tests/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,15 @@ static void test_PathCombineA(void)
ok(!lstrcmpA(str, "C:\\"), "Expected C:\\, got %s\n", str);
ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());

/* try relative paths */
/* try forward slashes */
SetLastError(0xdeadbeef);
lstrcpyA(dest, "control");
str = PathCombineA(dest, "../../../one/two/", "*");
ok(str == dest, "Expected str == dest, got %p\n", str);
ok(!lstrcmpA(str, "../../../one/two/\\*"), "Expected ../../../one/two/\\*, got %s\n", str);
ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());

memset(too_long, 'a', LONG_LEN);
too_long[LONG_LEN - 1] = '\0';

Expand Down Expand Up @@ -1039,6 +1048,22 @@ static void test_PathCanonicalizeA(void)
!lstrcmpA(dest, "C:\\one/"), /* Vista */
"Expected \"C:\\one/.\" or \"C:\\one/\", got \"%s\"\n", dest);

/* try relative forward slashes */
lstrcpyA(dest, "test");
SetLastError(0xdeadbeef);
res = PathCanonicalizeA(dest, "../../one/two/");
ok(res, "Expected success\n");
ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
ok(!lstrcmpA(dest, "../../one/two/"), "Expected ../../one/two/, got %s\n", dest);

/* try relative forward slashes */
lstrcpyA(dest, "test");
SetLastError(0xdeadbeef);
res = PathCanonicalizeA(dest, "../../one/two/\\*");
ok(res, "Expected success\n");
ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
ok(!lstrcmpA(dest, "../../one/two/\\*"), "Expected ../../one/two/\\*, got %s\n", dest);

/* try forward slashes with change dirs
* NOTE: if there is a forward slash in between two backslashes,
* everything in between the two backslashes is considered on dir
Expand Down

0 comments on commit 35803e7

Please sign in to comment.