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