Commit 542998ee authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Accept NULL buffer for size queries in WinHttpCreateUrl.

parent f2c00546
......@@ -118,7 +118,7 @@ static void WinHttpCreateUrl_test( void )
{
URL_COMPONENTS uc;
WCHAR *url;
DWORD len;
DWORD len, err;
BOOL ret;
/* NULL components */
......@@ -144,22 +144,33 @@ static void WinHttpCreateUrl_test( void )
ok( !ret, "expected failure\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
/* valid components, NULL url */
/* valid components, NULL url, insufficient length */
len = 0;
SetLastError( 0xdeadbeef );
ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
ok( !ret, "expected failure\n" );
ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
ok( len == 57, "expected len 57 got %u\n", len );
/* valid components, NULL url, sufficient length */
SetLastError( 0xdeadbeef );
len = 256;
ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
err = GetLastError();
ok( !ret, "expected failure\n" );
ok( err == ERROR_INVALID_PARAMETER || broken(err == ERROR_INSUFFICIENT_BUFFER) /* < win7 */,
"expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
ok( len == 256 || broken(len == 57) /* < win7 */, "expected len 256 got %u\n", len );
/* correct size, NULL url */
fill_url_components( &uc );
SetLastError( 0xdeadbeef );
ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
err = GetLastError();
ok( !ret, "expected failure\n" );
ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
ok( err == ERROR_INVALID_PARAMETER || broken(err == ERROR_INSUFFICIENT_BUFFER) /* < win7 */,
"expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
ok( len == 256 || broken(len == 57) /* < win7 */, "expected len 256 got %u\n", len );
/* valid components, allocated url, short length */
SetLastError( 0xdeadbeef );
......
......@@ -417,13 +417,12 @@ BOOL WINAPI WinHttpCreateUrl( LPURL_COMPONENTS uc, DWORD flags, LPWSTR url, LPDW
{
static const WCHAR formatW[] = {'%','u',0};
static const WCHAR twoslashW[] = {'/','/'};
DWORD len;
INTERNET_SCHEME scheme;
TRACE("%p, 0x%08x, %p, %p\n", uc, flags, url, required);
if (!uc || uc->dwStructSize != sizeof(URL_COMPONENTS) || !required || !url)
if (!uc || uc->dwStructSize != sizeof(URL_COMPONENTS) || !required)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
......@@ -437,6 +436,11 @@ BOOL WINAPI WinHttpCreateUrl( LPURL_COMPONENTS uc, DWORD flags, LPWSTR url, LPDW
set_last_error( ERROR_INSUFFICIENT_BUFFER );
return FALSE;
}
if (!url)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
}
url[0] = 0;
*required = len;
......
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