Commit 31c49c28 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

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

parent c1a46db9
...@@ -661,7 +661,7 @@ void WINAPI PathStripPathA(LPSTR lpszPath) ...@@ -661,7 +661,7 @@ void WINAPI PathStripPathA(LPSTR lpszPath)
if (lpszPath) if (lpszPath)
{ {
LPSTR lpszFileName = PathFindFileNameA(lpszPath); LPSTR lpszFileName = PathFindFileNameA(lpszPath);
if(lpszFileName) if(lpszFileName != lpszPath)
RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1); RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
} }
} }
...@@ -677,7 +677,7 @@ void WINAPI PathStripPathW(LPWSTR lpszPath) ...@@ -677,7 +677,7 @@ void WINAPI PathStripPathW(LPWSTR lpszPath)
TRACE("(%s)\n", debugstr_w(lpszPath)); TRACE("(%s)\n", debugstr_w(lpszPath));
lpszFileName = PathFindFileNameW(lpszPath); lpszFileName = PathFindFileNameW(lpszPath);
if(lpszFileName) if(lpszFileName != lpszPath)
RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR)); RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
} }
......
...@@ -1639,6 +1639,19 @@ static void test_PathIsRelativeW(void) ...@@ -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) START_TEST(path)
{ {
HMODULE hShlwapi = GetModuleHandleA("shlwapi.dll"); HMODULE hShlwapi = GetModuleHandleA("shlwapi.dll");
...@@ -1684,4 +1697,5 @@ START_TEST(path) ...@@ -1684,4 +1697,5 @@ START_TEST(path)
test_PathUnExpandEnvStrings(); test_PathUnExpandEnvStrings();
test_PathIsRelativeA(); test_PathIsRelativeA();
test_PathIsRelativeW(); test_PathIsRelativeW();
test_PathStripPathA();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment