Commit c23c43e9 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

wininet: Allocate returned options strings with the process heap.

parent 69a73009
...@@ -2522,6 +2522,37 @@ static WCHAR *get_proxy_autoconfig_url(void) ...@@ -2522,6 +2522,37 @@ static WCHAR *get_proxy_autoconfig_url(void)
return ret; return ret;
} }
static WCHAR *copy_optionW(WCHAR *value)
{
DWORD len;
void *tmp;
if (!value)
return NULL;
len = (wcslen(value) + 1) * sizeof(WCHAR);
if (!(tmp = HeapAlloc(GetProcessHeap(), 0, len)))
return NULL;
return memcpy(tmp, value, len);
}
static char *copy_optionA(WCHAR *value)
{
DWORD len;
void *tmp;
if (!value)
return NULL;
len = wcslen(value) * 3 + 1;
if (!(tmp = HeapAlloc(GetProcessHeap(), 0, len)))
return NULL;
WideCharToMultiByte(CP_ACP, 0, value, -1, tmp, len, NULL, NULL);
return tmp;
}
static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode) static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
{ {
/* FIXME: This function currently handles more options than it should. Options requiring /* FIXME: This function currently handles more options than it should. Options requiring
...@@ -2642,25 +2673,25 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u ...@@ -2642,25 +2673,25 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u
case INTERNET_PER_CONN_PROXY_SERVER: case INTERNET_PER_CONN_PROXY_SERVER:
if (unicode) if (unicode)
optionW->Value.pszValue = wcsdup(pi.proxy); optionW->Value.pszValue = copy_optionW(pi.proxy);
else else
optionA->Value.pszValue = strdupWtoA(pi.proxy); optionA->Value.pszValue = copy_optionA(pi.proxy);
break; break;
case INTERNET_PER_CONN_PROXY_BYPASS: case INTERNET_PER_CONN_PROXY_BYPASS:
if (unicode) if (unicode)
optionW->Value.pszValue = wcsdup(pi.proxyBypass); optionW->Value.pszValue = copy_optionW(pi.proxyBypass);
else else
optionA->Value.pszValue = strdupWtoA(pi.proxyBypass); optionA->Value.pszValue = copy_optionA(pi.proxyBypass);
break; break;
case INTERNET_PER_CONN_AUTOCONFIG_URL: case INTERNET_PER_CONN_AUTOCONFIG_URL:
if (!url) if (!url)
optionW->Value.pszValue = NULL; optionW->Value.pszValue = NULL;
else if (unicode) else if (unicode)
optionW->Value.pszValue = wcsdup(url); optionW->Value.pszValue = copy_optionW(url);
else else
optionA->Value.pszValue = strdupWtoA(url); optionA->Value.pszValue = copy_optionA(url);
break; break;
case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS: case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
......
...@@ -1307,6 +1307,9 @@ static void test_Option_PerConnectionOption(void) ...@@ -1307,6 +1307,9 @@ static void test_Option_PerConnectionOption(void)
list.pOptions[1].Value.dwValue); list.pOptions[1].Value.dwValue);
verifyProxyEnable(1); verifyProxyEnable(1);
ret = HeapValidate(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
ok(ret, "HeapValidate failed, last error %lu\n", GetLastError());
HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue); HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
HeapFree(GetProcessHeap(), 0, list.pOptions); HeapFree(GetProcessHeap(), 0, list.pOptions);
......
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