Commit c5fa3ec2 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Set last error for invalid URLs passed to WinHttpCrackUrl.

parent d1d0e335
......@@ -557,6 +557,19 @@ static void WinHttpCrackUrl_test( void )
ok( ret, "WinHttpCrackUrl failed\n" );
ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
reset_url_components( &uc );
SetLastError( 0xdeadbeef );
ret = WinHttpCrackUrl( empty, 0, 0, &uc );
error = GetLastError();
ok( !ret, "WinHttpCrackUrl succeeded\n" );
ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
reset_url_components( &uc );
SetLastError( 0xdeadbeef );
ret = WinHttpCrackUrl( http, 0, 0, &uc );
error = GetLastError();
ok( !ret, "WinHttpCrackUrl succeeded\n" );
ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
}
START_TEST(url)
......
......@@ -82,7 +82,7 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
if (flags & ICU_ESCAPE) FIXME("flag ICU_ESCAPE not supported\n");
if (!url || !url[0] || !uc || uc->dwStructSize != sizeof(URL_COMPONENTS))
if (!url || !uc || uc->dwStructSize != sizeof(URL_COMPONENTS))
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
......@@ -114,12 +114,18 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
}
HeapFree( GetProcessHeap(), 0, url_tmp );
}
if (!(p = strchrW( url, ':' ))) return FALSE;
if (!(p = strchrW( url, ':' )))
{
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;
else goto exit;
else
{
set_last_error( ERROR_WINHTTP_UNRECOGNIZED_SCHEME );
goto exit;
}
if (!(set_component( &uc->lpszScheme, &uc->dwSchemeLength, (WCHAR *)url, p - url, flags ))) goto exit;
p++; /* skip ':' */
......
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