Henri Verbeet : wininet: Treat an empty username as NULL in FTP_Connect().

Alexandre Julliard julliard at winehq.org
Tue Nov 18 09:27:13 CST 2008


Module: wine
Branch: master
Commit: 369da3aeb9d044866f53bc250768e18401027201
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=369da3aeb9d044866f53bc250768e18401027201

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Tue Nov 18 09:27:59 2008 +0100

wininet: Treat an empty username as NULL in FTP_Connect().

---

 dlls/wininet/ftp.c       |    4 ++--
 dlls/wininet/tests/ftp.c |   23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index cb24782..9ad34df 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -2256,7 +2256,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
 
     assert( hIC->hdr.htype == WH_HINIT );
 
-    if (NULL == lpszUserName && NULL != lpszPassword)
+    if ((!lpszUserName || !strlenW(lpszUserName)) && lpszPassword)
     {
 	INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
         goto lerror;
@@ -2302,7 +2302,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
         if(hIC->lpszProxyBypass)
             FIXME("Proxy bypass is ignored.\n");
     }
-    if ( !lpszUserName) {
+    if (!lpszUserName || !strlenW(lpszUserName)) {
         HKEY key;
         WCHAR szPassword[MAX_PATH];
         DWORD len = sizeof(szPassword);
diff --git a/dlls/wininet/tests/ftp.c b/dlls/wininet/tests/ftp.c
index 335215e..f7dc9c9 100644
--- a/dlls/wininet/tests/ftp.c
+++ b/dlls/wininet/tests/ftp.c
@@ -66,6 +66,8 @@ static void test_connect(HINTERNET hInternet)
      * anonymous : NULL
      * NULL      : IEUser@
      * NULL      : NULL
+     * ""        : IEUser@
+     * ""        : NULL
      */
 
     SetLastError(0xdeadbeef);
@@ -85,6 +87,13 @@ static void test_connect(HINTERNET hInternet)
     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
         "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
+    SetLastError(0xdeadbeef);
+    hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", "IEUser@",
+            INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
+    ok(!hFtp, "Expected InternetConnect to fail\n");
+    ok(GetLastError() == ERROR_INVALID_PARAMETER,
+        "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
+
     /* Using a NULL username and password will be interpreted as anonymous ftp. The username will be 'anonymous' the password
      * is created via some simple heuristics (see dlls/wininet/ftp.c).
      * On Wine this registry key is not set by default so (NULL, NULL) will result in anonymous ftp with an (most likely) not
@@ -103,6 +112,20 @@ static void test_connect(HINTERNET hInternet)
     ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError());
     ok ( GetLastError() == ERROR_SUCCESS,
         "ERROR_SUCCESS, got %d\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "", NULL,
+            INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
+    if (!hFtp)
+    {
+        ok(GetLastError() == ERROR_INTERNET_LOGIN_FAILURE,
+                "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError());
+    }
+    else
+    {
+        ok(GetLastError() == ERROR_SUCCESS,
+                "Expected ERROR_SUCCESS, got %d\n", GetLastError());
+    }
 }
 
 static void test_createdir(HINTERNET hFtp, HINTERNET hConnect)




More information about the wine-cvs mailing list