[PATCH v2 1/3] wininet/tests: Test InternetCrackUrl when given a bogus length
Tim Clem
tclem at codeweavers.com
Fri Jul 2 18:12:03 CDT 2021
Windows will stop processing at the first null, even when given an
explicit length.
Signed-off-by: Tim Clem <tclem at codeweavers.com>
---
Added some more thorough tests. In the case that amounts to
InternetCrackUrlA("http://", ...), Wine does the wrong thing, even
with these patches. Windows rejects that, but we seemingly have no
check for an empty hostname. I left that test as todo_wine.
dlls/wininet/tests/url.c | 57 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/dlls/wininet/tests/url.c b/dlls/wininet/tests/url.c
index bce7dc76c59..6927ca5e6e8 100644
--- a/dlls/wininet/tests/url.c
+++ b/dlls/wininet/tests/url.c
@@ -653,6 +653,26 @@ static void InternetCrackUrl_test(void)
GLE = GetLastError();
ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
ok(GLE == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "Expected GLE to represent a failure\n");
+
+ /* Windows treats dwUrlLength as a maximum - if there is a null before
+ * that length, it stops there. */
+ copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 1024, 1024);
+ ret = InternetCrackUrlA("http://x.org", 13 /* includes the nul */, 0, &urlComponents);
+ ok(ret, "InternetCrackUrlA failed with error %d\n", GetLastError());
+ todo_wine
+ ok(urlComponents.dwHostNameLength == 5,
+ "Expected dwHostNameLength of 5, got %d\n", urlComponents.dwHostNameLength);
+
+ copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 1024, 1024);
+ ret = InternetCrackUrlA("http://\0x.org", 13, 0, &urlComponents);
+ todo_wine ok(ret == FALSE, "Expected InternetCrackUrlA to fail\n");
+
+ copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 1024, 1024);
+ ret = InternetCrackUrlA("http://x.org\0/x", 15, 0, &urlComponents);
+ ok(ret, "InternetCrackUrlA failed with error %d\n", GetLastError());
+ todo_wine
+ ok(urlComponents.dwUrlPathLength == 0,
+ "Expected dwUrlPathLength of 0, got %d\n", urlComponents.dwUrlPathLength);
}
static void InternetCrackUrlW_test(void)
@@ -664,6 +684,8 @@ static void InternetCrackUrlW_test(void)
'U','L','T', 0 };
static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
static const WCHAR url3[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
+ static const WCHAR url4[] = { 'h','t','t','p',':','/','/',0,'x','.','o','r','g',0 };
+ static const WCHAR url5[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0,'/','x',0 };
URL_COMPONENTSW comp;
WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
DWORD error;
@@ -825,6 +847,41 @@ static void InternetCrackUrlW_test(void)
ok(r, "InternetCrackUrlW failed unexpectedly\n");
ok(!strcmp_wa(host, "x.org"), "host is %s, should be x.org\n", wine_dbgstr_w(host));
todo_wine ok(urlpart[0] == 0, "urlpart should be empty\n");
+
+ /* Windows treats dwUrlLength as a maximum - if there is a null before
+ * that length, it stops there. */
+ host[0] = 0;
+ memset(&comp, 0, sizeof(comp));
+ comp.dwStructSize = sizeof(comp);
+ comp.lpszHostName = host;
+ comp.dwHostNameLength = ARRAY_SIZE(host);
+ r = InternetCrackUrlW(url3, 13 /* includes the nul */, 0, &comp);
+ ok(r, "InternetCrackUrlW failed with error %d\n", GetLastError());
+ todo_wine
+ ok(comp.dwHostNameLength == 5,
+ "Expected dwHostNameLength of 5, got %d\n", comp.dwHostNameLength);
+
+ host[0] = 0;
+ memset(&comp, 0, sizeof(comp));
+ comp.dwStructSize = sizeof(comp);
+ comp.lpszHostName = host;
+ comp.dwHostNameLength = ARRAY_SIZE(host);
+ r = InternetCrackUrlW(url4, 13, 0, &comp);
+ todo_wine ok(r == FALSE, "Expected InternetCrackUrlW to fail\n");
+
+ host[0] = 0;
+ urlpart[0] = 0;
+ memset(&comp, 0, sizeof(comp));
+ comp.dwStructSize = sizeof(comp);
+ comp.lpszHostName = host;
+ comp.dwHostNameLength = ARRAY_SIZE(host);
+ comp.lpszUrlPath = urlpart;
+ comp.dwUrlPathLength = ARRAY_SIZE(urlpart);
+ r = InternetCrackUrlW(url5, 15, 0, &comp);
+ ok(r, "InternetCrackUrlW failed with error %d\n", GetLastError());
+ todo_wine
+ ok(comp.dwUrlPathLength == 0,
+ "Expected dwUrlPathLength of 0, got %d\n", comp.dwUrlPathLength);
}
static void fill_url_components(URL_COMPONENTSA *lpUrlComponents)
--
2.32.0
More information about the wine-devel
mailing list