[1/2] wininet: fix FtpGetCurrentDirectoryW to handle bad input

Zac Brown zac at zacbrown.org
Sat Dec 1 16:21:07 CST 2007


Hi,

This patch fixes FtpGetCurrentDirectoryW to keep it from crashing upon use of
calling it with NULL/0 input.

Note: some of the functionality is not complete, and in the [2/2] patch,
the test for input that still fails is wrapped in todo_wine.

-Zac Brown

---
 dlls/wininet/ftp.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index 39fbc90..6178f5e 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -885,12 +885,30 @@ BOOL WINAPI FtpGetCurrentDirectoryW(HINTERNET hFtpSession, LPWSTR lpszCurrentDir
     TRACE("len(%d)\n", *lpdwCurrentDirectory);

     lpwfs = (LPWININETFTPSESSIONW) WININET_GetObject( hFtpSession );
-    if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
+    if (NULL == lpwfs)
+    {
+        INTERNET_SetLastError(ERROR_INVALID_HANDLE);
+        goto lend;
+    }
+
+    if (WH_HFTPSESSION != lpwfs->hdr.htype)
     {
         INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
         goto lend;
     }
+
+    if (!lpdwCurrentDirectory)
+    {
+        INTERNET_SetLastError(ERROR_INVALID_PARAMETER);	
+        goto lend;
+    }

+    if (lpszCurrentDirectory == NULL)
+    {
+        INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
+        goto lend;
+    }
+
     if (lpwfs->download_in_progress != NULL)
     {
         INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
-- 
1.5.2.5



More information about the wine-patches mailing list