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

Alexandre Julliard julliard at wine.codeweavers.com
Thu Oct 29 09:32:11 CDT 2015


Module: wine
Branch: master
Commit: 31c49c2851d7557271dbf44a6c9239c6bcc24d67
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=31c49c2851d7557271dbf44a6c9239c6bcc24d67

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Oct 28 20:05:12 2015 +0100

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

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/shlwapi/path.c       |  4 ++--
 dlls/shlwapi/tests/path.c | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/dlls/shlwapi/path.c b/dlls/shlwapi/path.c
index dae949a..3c07bb8 100644
--- a/dlls/shlwapi/path.c
+++ b/dlls/shlwapi/path.c
@@ -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));
 }
 
diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c
index ab4ae47..03079a3 100644
--- a/dlls/shlwapi/tests/path.c
+++ b/dlls/shlwapi/tests/path.c
@@ -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();
 }




More information about the wine-cvs mailing list