Commit 40119690 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

shlwapi: Make UrlCanonicalizeA working with long urls (>INTERNET_MAX_URL_LENGTH).

parent fc543890
...@@ -232,40 +232,34 @@ HRESULT WINAPI ParseURLW(LPCWSTR x, PARSEDURLW *y) ...@@ -232,40 +232,34 @@ HRESULT WINAPI ParseURLW(LPCWSTR x, PARSEDURLW *y)
HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized,
LPDWORD pcchCanonicalized, DWORD dwFlags) LPDWORD pcchCanonicalized, DWORD dwFlags)
{ {
LPWSTR base, canonical; LPWSTR url, canonical;
HRESULT ret; HRESULT ret;
DWORD len, len2; DWORD len;
TRACE("(%s, %p, %p, 0x%08x) *pcchCanonicalized: %d\n", debugstr_a(pszUrl), pszCanonicalized, TRACE("(%s, %p, %p, 0x%08x) *pcchCanonicalized: %d\n", debugstr_a(pszUrl), pszCanonicalized,
pcchCanonicalized, dwFlags, pcchCanonicalized ? *pcchCanonicalized : -1); pcchCanonicalized, dwFlags, pcchCanonicalized ? *pcchCanonicalized : -1);
if(!pszUrl || !pszCanonicalized || !pcchCanonicalized) if(!pszUrl || !pszCanonicalized || !pcchCanonicalized || !*pcchCanonicalized)
return E_INVALIDARG; return E_INVALIDARG;
base = HeapAlloc(GetProcessHeap(), 0, len = strlen(pszUrl)+1;
(2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR)); url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
canonical = base + INTERNET_MAX_URL_LENGTH; canonical = HeapAlloc(GetProcessHeap(), 0, *pcchCanonicalized*sizeof(WCHAR));
if(!url || !canonical) {
HeapFree(GetProcessHeap(), 0, url);
HeapFree(GetProcessHeap(), 0, canonical);
return E_OUTOFMEMORY;
}
MultiByteToWideChar(0, 0, pszUrl, -1, base, INTERNET_MAX_URL_LENGTH); MultiByteToWideChar(0, 0, pszUrl, -1, url, len);
len = INTERNET_MAX_URL_LENGTH;
ret = UrlCanonicalizeW(base, canonical, &len, dwFlags); ret = UrlCanonicalizeW(url, canonical, pcchCanonicalized, dwFlags);
if (ret != S_OK) { if(ret == S_OK)
*pcchCanonicalized = len * 2; WideCharToMultiByte(0, 0, canonical, -1, pszCanonicalized,
HeapFree(GetProcessHeap(), 0, base); *pcchCanonicalized+1, 0, 0);
return ret;
}
len2 = WideCharToMultiByte(0, 0, canonical, -1, 0, 0, 0, 0); HeapFree(GetProcessHeap(), 0, canonical);
if (len2 > *pcchCanonicalized) { return ret;
*pcchCanonicalized = len2;
HeapFree(GetProcessHeap(), 0, base);
return E_POINTER;
}
WideCharToMultiByte(0, 0, canonical, -1, pszCanonicalized, *pcchCanonicalized, 0, 0);
*pcchCanonicalized = len;
HeapFree(GetProcessHeap(), 0, base);
return S_OK;
} }
/************************************************************************* /*************************************************************************
......
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