diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 76426253d50..e58fca1563a 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -812,17 +812,26 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, DWORD dwService, DWORD dwFlags, DWORD dwContext) { LPWININETAPPINFOW hIC; - HINTERNET rc = (HINTERNET) NULL; + HINTERNET rc = NULL; TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName), nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword), dwService, dwFlags, dwContext); + if (!lpszServerName) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + /* Clear any error information */ INTERNET_SetLastError(0); hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet ); if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) ) + { + SetLastError(ERROR_INVALID_HANDLE); goto lend; + } switch (dwService) { diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 293656ccf46..43d17d6c4d0 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -119,8 +119,36 @@ static void test_get_cookie(void) ret ? "TRUE" : "FALSE", GetLastError()); } +static void test_null(void) +{ + HINTERNET hi, hc; + static const WCHAR szServer[] = { 's','e','r','v','e','r',0 }; + + hi = InternetOpenW(NULL, 0, NULL, NULL, 0); + ok(hi != NULL, "open failed\n"); + + hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n"); + ok(hc == NULL, "connect failed\n"); + + hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n"); + ok(hc == NULL, "connect failed\n"); + + hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n"); + ok(hc == NULL, "connect failed\n"); + + hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0); + ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n"); + ok(hc == NULL, "connect failed\n"); + + InternetCloseHandle(hi); +} + START_TEST(internet) { InternetQueryOptionA_test(); test_get_cookie(); + test_null(); }