[PATCH] shlwapi: Handle buffer overflow on A->W converter

Marcus Meissner marcus at jet.franken.de
Sat Mar 1 16:12:26 CST 2008


Hi,

Handle buffer overflow on A->W converter.

It still changes Lasterror, which the original code
does not do, but well, this is a cleaner patch.

Ciao, Marcus
---
 dlls/shlwapi/path.c       |    7 ++++++-
 dlls/shlwapi/tests/path.c |    2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/dlls/shlwapi/path.c b/dlls/shlwapi/path.c
index b2005c1..ae9c991 100644
--- a/dlls/shlwapi/path.c
+++ b/dlls/shlwapi/path.c
@@ -2344,7 +2344,12 @@ BOOL WINAPI PathCanonicalizeA(LPSTR lpszBuf, LPCSTR lpszPath)
   {
     WCHAR szPath[MAX_PATH];
     WCHAR szBuff[MAX_PATH];
-    MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
+    int ret = MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
+
+    if (!ret) {
+	WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
+	return FALSE;
+    }
     bRet = PathCanonicalizeW(szBuff, szPath);
     WideCharToMultiByte(CP_ACP,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
   }
diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c
index 82112a5..b2d2a9e 100644
--- a/dlls/shlwapi/tests/path.c
+++ b/dlls/shlwapi/tests/path.c
@@ -908,9 +908,9 @@ static void test_PathCanonicalizeA(void)
     lstrcpy(dest, "test");
     SetLastError(0xdeadbeef);
     res = PathCanonicalizeA(dest, too_long);
+    ok(!res, "Expected failure\n");
     todo_wine
     {
-        ok(!res, "Expected failure\n");
         ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
     }
     ok(lstrlen(too_long) == LONG_LEN - 1, "Expected length LONG_LEN - 1, got %i\n", lstrlen(too_long));
-- 
1.5.2.4



More information about the wine-patches mailing list