Skip to content

Commit

Permalink
wininet: Resize buffer when call to InternetCanonicalizeUrlW fails in…
Browse files Browse the repository at this point in the history
… InternetCrackUrlW.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=40598
Signed-off-by: Alistair Leslie-Hughes <[email protected]>
Signed-off-by: Jacek Caban <[email protected]>
Signed-off-by: Alexandre Julliard <[email protected]>
  • Loading branch information
mmueller2012 authored and julliard committed Sep 7, 2018
1 parent 24f3d50 commit bfe8510
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 18 additions & 3 deletions dlls/wininet/internet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwF

if (dwFlags & ICU_DECODE)
{
WCHAR *url_tmp;
WCHAR *url_tmp, *buffer;
DWORD len = dwUrlLength + 1;
BOOL ret;

Expand All @@ -1673,9 +1673,24 @@ BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwF
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
ret = InternetCanonicalizeUrlW(url_tmp, url_tmp, &len, ICU_DECODE | ICU_NO_ENCODE);

buffer = url_tmp;
ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
buffer = heap_alloc(len * sizeof(WCHAR));
if (!buffer)
{
SetLastError(ERROR_OUTOFMEMORY);
heap_free(url_tmp);
return FALSE;
}
ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
}
if (ret)
ret = InternetCrackUrlW(url_tmp, len, dwFlags & ~ICU_DECODE, lpUC);
ret = InternetCrackUrlW(buffer, len, dwFlags & ~ICU_DECODE, lpUC);

if (buffer != url_tmp) heap_free(buffer);
heap_free(url_tmp);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions dlls/wininet/tests/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ static void InternetCrackUrlW_test(void)
comp.lpszUrlPath = urlpart;
comp.dwUrlPathLength = ARRAY_SIZE(urlpart);
r = InternetCrackUrlW(url3, 0, ICU_DECODE, &comp);
todo_wine ok(r, "InternetCrackUrlW failed unexpectedly\n");
todo_wine ok(!strcmp_wa(host, "x.org"), "host is %s, should be x.org\n", wine_dbgstr_w(host));
ok(urlpart[0] == 0, "urlpart should be empty\n");
ok(r, "InternetCrackUrlW failed unexpectedly\n");
ok(!strcmp_wa(host, "x.org"), "host is %s, should be x.org\n", wine_dbgstr_w(host));
todo_wine ok(urlpart[0] == 0, "urlpart should be empty\n");
}

static void fill_url_components(URL_COMPONENTSA *lpUrlComponents)
Expand Down

0 comments on commit bfe8510

Please sign in to comment.