Hans Leidekker : winhttp: Set last error for invalid URLs passed to WinHttpCrackUrl.
Alexandre Julliard
julliard at winehq.org
Mon Jan 5 10:24:38 CST 2009
Module: wine
Branch: master
Commit: c5fa3ec216d8040198d755de5282111ccdb3a5f0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c5fa3ec216d8040198d755de5282111ccdb3a5f0
Author: Hans Leidekker <hans at codeweavers.com>
Date: Mon Jan 5 16:00:02 2009 +0100
winhttp: Set last error for invalid URLs passed to WinHttpCrackUrl.
---
dlls/winhttp/tests/url.c | 13 +++++++++++++
dlls/winhttp/url.c | 16 +++++++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
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-cvs
mailing list