Commit 069df699 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Only set the scheme if we have a valid URL.

parent 465f85e8
......@@ -658,6 +658,41 @@ static void WinHttpCrackUrl_test( void )
ok( uc.dwUrlPathLength == 5, "unexpected length %u\n", uc.dwUrlPathLength );
ok( !uc.lpszExtraInfo[0], "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
ok( uc.dwExtraInfoLength == 0, "unexpected length %u\n", uc.dwExtraInfoLength );
uc.dwStructSize = sizeof(uc);
uc.lpszScheme = scheme;
uc.dwSchemeLength = 0;
uc.nScheme = 0;
uc.lpszHostName = NULL;
uc.dwHostNameLength = 0;
uc.nPort = 0;
uc.lpszUserName = NULL;
uc.dwUserNameLength = ~0u;
uc.lpszPassword = NULL;
uc.dwPasswordLength = ~0u;
uc.lpszUrlPath = NULL;
uc.dwUrlPathLength = 0;
uc.lpszExtraInfo = NULL;
uc.dwExtraInfoLength = 0;
SetLastError( 0xdeadbeef );
ret = WinHttpCrackUrl( url15, 0, 0, &uc );
error = GetLastError();
ok( !ret, "WinHttpCrackUrl succeeded\n" );
ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
ok( !lstrcmpW( uc.lpszScheme, http ), "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
ok( !uc.dwSchemeLength, "unexpected length %u\n", uc.dwSchemeLength );
ok( uc.nScheme == 0, "unexpected scheme %u\n", uc.nScheme );
ok( !uc.lpszHostName, "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
ok( uc.dwHostNameLength == 0, "unexpected length %u\n", uc.dwHostNameLength );
ok( uc.nPort == 0, "unexpected port %u\n", uc.nPort );
ok( !uc.lpszUserName, "unexpected username\n" );
ok( uc.dwUserNameLength == ~0u, "unexpected length %u\n", uc.dwUserNameLength );
ok( !uc.lpszPassword, "unexpected password\n" );
ok( uc.dwPasswordLength == ~0u, "unexpected length %u\n", uc.dwPasswordLength );
ok( !uc.lpszUrlPath, "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
ok( uc.dwUrlPathLength == 0, "unexpected length %u\n", uc.dwUrlPathLength );
ok( !uc.lpszExtraInfo, "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
ok( uc.dwExtraInfoLength == 0, "unexpected length %u\n", uc.dwExtraInfoLength );
}
START_TEST(url)
......
......@@ -36,6 +36,11 @@ static const WCHAR scheme_https[] = {'h','t','t','p','s',0};
static BOOL set_component( WCHAR **str, DWORD *str_len, WCHAR *value, DWORD len, DWORD flags )
{
if (*str && !*str_len)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
}
if (!*str_len) return TRUE;
if (!*str)
{
......@@ -174,6 +179,7 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
{
BOOL ret = FALSE;
WCHAR *p, *q, *r, *url_decoded = NULL, *url_escaped = NULL;
INTERNET_SCHEME scheme = 0;
TRACE("%s, %d, %x, %p\n", debugstr_w(url), len, flags, uc);
......@@ -207,8 +213,8 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
set_last_error( ERROR_WINHTTP_UNRECOGNIZED_SCHEME );
return FALSE;
}
if (p - url == 4 && !strncmpiW( url, scheme_http, 4 )) uc->nScheme = INTERNET_SCHEME_HTTP;
else if (p - url == 5 && !strncmpiW( url, scheme_https, 5 )) uc->nScheme = INTERNET_SCHEME_HTTPS;
if (p - url == 4 && !strncmpiW( url, scheme_http, 4 )) scheme = INTERNET_SCHEME_HTTP;
else if (p - url == 5 && !strncmpiW( url, scheme_https, 5 )) scheme = INTERNET_SCHEME_HTTPS;
else
{
set_last_error( ERROR_WINHTTP_UNRECOGNIZED_SCHEME );
......@@ -252,8 +258,8 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
else
{
if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, q - p, flags ))) goto exit;
if (uc->nScheme == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
if (uc->nScheme == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
if (scheme == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
if (scheme == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
}
if ((r = memchrW( q, '?', len - (q - url) )))
......@@ -278,8 +284,8 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
else
{
if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, len - (p - url), flags ))) goto exit;
if (uc->nScheme == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
if (uc->nScheme == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
if (scheme == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
if (scheme == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
}
if (!(set_component( &uc->lpszUrlPath, &uc->dwUrlPathLength, (WCHAR *)url + len, 0, flags ))) goto exit;
if (!(set_component( &uc->lpszExtraInfo, &uc->dwExtraInfoLength, (WCHAR *)url + len, 0, flags ))) goto exit;
......@@ -295,6 +301,7 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
debugstr_wn( uc->lpszExtraInfo, uc->dwExtraInfoLength ));
exit:
if (ret) uc->nScheme = scheme;
heap_free( url_decoded );
heap_free( url_escaped );
return ret;
......
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