Hans Leidekker : winhttp: Fix default port corner cases in WinHttpCrackUrl().
Alexandre Julliard
julliard at winehq.org
Tue Jun 14 15:56:50 CDT 2022
Module: wine
Branch: master
Commit: 2fccd2cb1067ca3e07b0f978ca4082dfeea482ca
URL: https://source.winehq.org/git/wine.git/?a=commit;h=2fccd2cb1067ca3e07b0f978ca4082dfeea482ca
Author: Hans Leidekker <hans at codeweavers.com>
Date: Sat Jun 4 16:07:38 2022 +0200
winhttp: Fix default port corner cases in WinHttpCrackUrl().
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
dlls/winhttp/tests/url.c | 9 ++++++++-
dlls/winhttp/url.c | 18 ++++++++++++++----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/dlls/winhttp/tests/url.c b/dlls/winhttp/tests/url.c
index 5f137dc6365..da51117e41e 100644
--- a/dlls/winhttp/tests/url.c
+++ b/dlls/winhttp/tests/url.c
@@ -61,6 +61,7 @@ static const WCHAR url18[] = L"http://%0D%1F%20%0A%7F%0D%0A";
static const WCHAR url19[] = L"http://?text=\xfb00";
static const WCHAR url20[] = L"http:///text=\xfb00";
static const WCHAR url21[] = L"https://nba2k19-ws.2ksports.com:19133/nba/v4/Accounts/get_account?x=3789526775265663876";
+static const WCHAR url22[] = L"http://winehq.org:/";
static const WCHAR url_k1[] = L"http://username:[email protected]/site/about";
static const WCHAR url_k2[] = L"http://www.winehq.org";
@@ -807,7 +808,13 @@ static void WinHttpCrackUrl_test( void )
uc.nPort = 1;
ret = WinHttpCrackUrl( url17, 0, 0, &uc );
ok( ret, "got %lu\n", GetLastError() );
- todo_wine ok( uc.nPort == 80, "got %u\n", uc.nPort );
+ ok( uc.nPort == 80, "got %u\n", uc.nPort );
+
+ reset_url_components( &uc );
+ uc.nPort = 1;
+ ret = WinHttpCrackUrl( url22, 0, 0, &uc );
+ ok( ret, "got %lu\n", GetLastError() );
+ ok( uc.nPort == 80, "got %u\n", uc.nPort );
memset( &uc, 0, sizeof(uc) );
uc.dwStructSize = sizeof(uc);
diff --git a/dlls/winhttp/url.c b/dlls/winhttp/url.c
index 9e7f5478dfe..4d10a17f6a0 100644
--- a/dlls/winhttp/url.c
+++ b/dlls/winhttp/url.c
@@ -280,13 +280,18 @@ BOOL WINAPI WinHttpCrackUrl( const WCHAR *url, DWORD len, DWORD flags, URL_COMPO
{
if ((err = set_component( &hostname, p, r - p, flags, &overflow ))) goto exit;
r++;
- if ((err = parse_port( r, q - r, &uc->nPort ))) goto exit;
+ if (!(q - r))
+ {
+ if (scheme_number == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
+ else if (scheme_number == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
+ }
+ else if ((err = parse_port( r, q - r, &uc->nPort ))) goto exit;
}
else
{
if ((err = set_component( &hostname, p, q - p, flags, &overflow ))) goto exit;
if (scheme_number == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
- if (scheme_number == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
+ else if (scheme_number == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
}
if ((r = wmemchr( q, '?', len - (q - url) )))
@@ -310,13 +315,18 @@ BOOL WINAPI WinHttpCrackUrl( const WCHAR *url, DWORD len, DWORD flags, URL_COMPO
{
if ((err = set_component( &hostname, p, r - p, flags, &overflow ))) goto exit;
r++;
- if ((err = parse_port( r, len - (r - url), &uc->nPort ))) goto exit;
+ if (!*r)
+ {
+ if (scheme_number == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
+ else if (scheme_number == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
+ }
+ else if ((err = parse_port( r, len - (r - url), &uc->nPort ))) goto exit;
}
else
{
if ((err = set_component( &hostname, p, len - (p - url), flags, &overflow ))) goto exit;
if (scheme_number == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
- if (scheme_number == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
+ else if (scheme_number == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
}
if ((err = set_component( &path, (WCHAR *)url + len, 0, flags, &overflow ))) goto exit;
if ((err = set_component( &extra, (WCHAR *)url + len, 0, flags, &overflow ))) goto exit;
More information about the wine-cvs
mailing list