diff --git a/dlls/winhttp/tests/url.c b/dlls/winhttp/tests/url.c index b76e82c407a..6bde1de70e4 100644 --- a/dlls/winhttp/tests/url.c +++ b/dlls/winhttp/tests/url.c @@ -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 ); diff --git a/dlls/winhttp/url.c b/dlls/winhttp/url.c index e7bb2a57115..32b30da0ce6 100644 --- a/dlls/winhttp/url.c +++ b/dlls/winhttp/url.c @@ -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;