Module: wine Branch: master Commit: 2b99331e9306e14a321911e5f2958269f1ce392f URL: http://source.winehq.org/git/wine.git/?a=commit;h=2b99331e9306e14a321911e5f2...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Jan 13 00:24:13 2011 +0100
shlwapi: Fixed handling A->W buffer in UrlCanonicalizeA (valgrind).
---
dlls/shlwapi/url.c | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/dlls/shlwapi/url.c b/dlls/shlwapi/url.c index ae2f408..bb5e633 100644 --- a/dlls/shlwapi/url.c +++ b/dlls/shlwapi/url.c @@ -42,6 +42,21 @@ HRESULT WINAPI MLBuildResURLW(LPCWSTR,HMODULE,DWORD,LPCWSTR,LPWSTR,DWORD);
WINE_DEFAULT_DEBUG_CHANNEL(shell);
+static inline WCHAR *heap_strdupAtoW(const char *str) +{ + LPWSTR ret = NULL; + + if(str) { + DWORD len; + + len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + } + + return ret; +} + /* The following schemes were identified in the native version of * SHLWAPI.DLL version 5.50 */ @@ -234,7 +249,6 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, { LPWSTR url, canonical; HRESULT ret; - DWORD len;
TRACE("(%s, %p, %p, 0x%08x) *pcchCanonicalized: %d\n", debugstr_a(pszUrl), pszCanonicalized, pcchCanonicalized, dwFlags, pcchCanonicalized ? *pcchCanonicalized : -1); @@ -242,8 +256,7 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, if(!pszUrl || !pszCanonicalized || !pcchCanonicalized || !*pcchCanonicalized) return E_INVALIDARG;
- len = strlen(pszUrl)+1; - url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); + url = heap_strdupAtoW(pszUrl); canonical = HeapAlloc(GetProcessHeap(), 0, *pcchCanonicalized*sizeof(WCHAR)); if(!url || !canonical) { HeapFree(GetProcessHeap(), 0, url); @@ -251,13 +264,12 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, return E_OUTOFMEMORY; }
- MultiByteToWideChar(0, 0, pszUrl, -1, url, len); - ret = UrlCanonicalizeW(url, canonical, pcchCanonicalized, dwFlags); if(ret == S_OK) WideCharToMultiByte(0, 0, canonical, -1, pszCanonicalized, *pcchCanonicalized+1, 0, 0);
+ HeapFree(GetProcessHeap(), 0, url); HeapFree(GetProcessHeap(), 0, canonical); return ret; }