Commit d6c0e815 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

wininet: Fail on URLs without a scheme.

parent 00b6d8eb
......@@ -1647,9 +1647,9 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR
*
*/
LPCWSTR lpszParam = NULL;
BOOL bIsAbsolute = FALSE;
BOOL found_colon = FALSE;
LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
LPCWSTR lpszcp = NULL;
LPCWSTR lpszcp = NULL, lpszNetLoc;
LPWSTR lpszUrl_decode = NULL;
DWORD dwUrlLength = dwUrlLength_orig;
......@@ -1699,9 +1699,9 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR
lpszap++;
continue;
}
if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
if (*lpszap == ':')
{
bIsAbsolute = TRUE;
found_colon = TRUE;
lpszcp = lpszap;
}
else
......@@ -1712,6 +1712,11 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR
break;
}
if(!found_colon){
SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
return 0;
}
lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
......@@ -1723,9 +1728,6 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR
SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
{
LPCWSTR lpszNetLoc;
/* Get scheme first. */
lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
......@@ -1855,14 +1857,6 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR
SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
}
}
else
{
SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
}
/* Here lpszcp points to:
*
......
......@@ -655,9 +655,7 @@ static void test_null(void)
ok(r == FALSE, "return wrong\n");
r = InternetSetCookieW(szServer, NULL, szServer);
todo_wine {
ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
}
ok(r == FALSE, "return wrong\n");
sz = 0;
......
......@@ -160,6 +160,9 @@ static const crack_url_test_t crack_url_tests[] = {
{"file:///C:/Program%20Files/Atmel/./Asdf.xml",
0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
"file", "", "", "", "C:\\Program Files\\Atmel\\.\\Asdf.xml", ""},
{"C:\\file.txt",
0, 1, INTERNET_SCHEME_UNKNOWN, -1, 0, -1, 0, -1, 0, -1, 0, 2, 9, -1, 0,
"C", "", "", "", "\\file.txt", ""}
};
static const WCHAR *w_str_of(const char *str)
......@@ -541,6 +544,7 @@ static void InternetCrackUrl_test(void)
SetLastError(0xdeadbeef);
urlComponents.dwStructSize = 0;
ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
GLE = GetLastError();
ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
......@@ -551,8 +555,25 @@ static void InternetCrackUrl_test(void)
SetLastError(0xdeadbeef);
urlComponents.dwStructSize = sizeof(urlComponents) + 1;
ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
GLE = GetLastError();
ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
SetLastError(0xdeadbeef);
memset(&urlComponents, 0, sizeof(urlComponents));
urlComponents.dwStructSize = sizeof(urlComponents);
ret = InternetCrackUrlA("file.txt", 0, 0, &urlComponents);
GLE = GetLastError();
ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
ok(GLE == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "Expected GLE to represent a failure\n");
SetLastError(0xdeadbeef);
memset(&urlComponents, 0, sizeof(urlComponents));
urlComponents.dwStructSize = sizeof(urlComponents);
ret = InternetCrackUrlA("www.winehq.org", 0, 0, &urlComponents);
GLE = GetLastError();
ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
ok(GLE == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "Expected GLE to represent a failure\n");
}
static void InternetCrackUrlW_test(void)
......@@ -690,12 +711,10 @@ static void InternetCrackUrlW_test(void)
comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
r = InternetCrackUrlW(url2, 0, 0, &comp);
todo_wine {
ok(!r, "InternetCrackUrl should have failed\n");
ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
"InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
GetLastError());
}
/* Test to see whether cracking a URL without a filename initializes urlpart */
urlpart[0]=0xba;
......
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