winhttp: Set last error for invalid URLs passed to WinHttpCrackUrl.
Hans Leidekker
hans at codeweavers.com
Mon Jan 5 09:00:02 CST 2009
diff --git a/dlls/winhttp/tests/url.c b/dlls/winhttp/tests/url.c
index 2765a67..14b20c1 100644
--- a/dlls/winhttp/tests/url.c
+++ b/dlls/winhttp/tests/url.c
@@ -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)
diff --git a/dlls/winhttp/url.c b/dlls/winhttp/url.c
index 9ed04cf..711987a 100644
--- a/dlls/winhttp/url.c
+++ b/dlls/winhttp/url.c
@@ -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 ':' */
More information about the wine-patches
mailing list