Module: wine Branch: master Commit: 542998ee24fe05cf230288c47538ccf18807ec64 URL: http://source.winehq.org/git/wine.git/?a=commit;h=542998ee24fe05cf230288c475...
Author: Hans Leidekker hans@codeweavers.com Date: Fri Jan 27 10:28:43 2017 +0100
winhttp: Accept NULL buffer for size queries in WinHttpCreateUrl.
Signed-off-by: Hans Leidekker hans@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/winhttp/tests/url.c | 27 +++++++++++++++++++-------- dlls/winhttp/url.c | 8 ++++++-- 2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/dlls/winhttp/tests/url.c b/dlls/winhttp/tests/url.c index b76e82c..6bde1de 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 e7bb2a5..32b30da 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;