shlwapi: Don't crash in PathStripPath when read-only string is passed and it's not modified.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2015-10-28 20:05:12 +01:00 committed by Alexandre Julliard
parent c1a46db98b
commit 31c49c2851
2 changed files with 16 additions and 2 deletions

View file

@ -661,7 +661,7 @@ void WINAPI PathStripPathA(LPSTR lpszPath)
if (lpszPath)
{
LPSTR lpszFileName = PathFindFileNameA(lpszPath);
if(lpszFileName)
if(lpszFileName != lpszPath)
RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
}
}
@ -677,7 +677,7 @@ void WINAPI PathStripPathW(LPWSTR lpszPath)
TRACE("(%s)\n", debugstr_w(lpszPath));
lpszFileName = PathFindFileNameW(lpszPath);
if(lpszFileName)
if(lpszFileName != lpszPath)
RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
}

View file

@ -1639,6 +1639,19 @@ static void test_PathIsRelativeW(void)
}
}
static void test_PathStripPathA(void)
{
const char const_path[] = "test";
char path[] = "short//path\\file.txt";
PathStripPathA(path);
ok(!strcmp(path, "file.txt"), "path = %s\n", path);
/* following test should not crash */
/* LavView 2013 depends on that behaviour */
PathStripPathA((char*)const_path);
}
START_TEST(path)
{
HMODULE hShlwapi = GetModuleHandleA("shlwapi.dll");
@ -1684,4 +1697,5 @@ START_TEST(path)
test_PathUnExpandEnvStrings();
test_PathIsRelativeA();
test_PathIsRelativeW();
test_PathStripPathA();
}