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