winiet/ftp.c question about a strncpy elimination
Peter Berg Larsen
pebl at math.ku.dk
Fri Apr 15 18:03:30 CDT 2005
What is the correct behaviour in FtpGetCurrentDirectory if the buffer
parameter is to small?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/ftpgetcurrentdirectory.asp
Index: dlls/wininet/ftp.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/ftp.c,v
retrieving revision 1.53
diff -u -r1.53 ftp.c
--- dlls/wininet/ftp.c 28 Mar 2005 14:58:52 -0000 1.53
+++ dlls/wininet/ftp.c 15 Apr 2005 20:15:04 -0000
@@ -813,6 +813,13 @@
* FTP_FtpGetCurrentDirectoryA (Internal)
*
* Retrieves the current directory
+ *
+ * Parameters
+ *
+ * lpwfs [I] Handle
+ * lpszCurrentDirectory [O] The absolute current path with '\0' termination.
+ * lpwdCurrentDirectory [I] The size of lpszCurrentDirectory.
+ * [O] The length of the absolute current path in lpszCurrentDirectory.
*
* RETURNS
* TRUE on success
@@ -864,11 +871,19 @@
}
len = lastpos - firstpos - 1;
- strncpyW(lpszCurrentDirectory, &lpszResponseBuffer[firstpos+1],
- len < *lpdwCurrentDirectory ? len : *lpdwCurrentDirectory);
- HeapFree(GetProcessHeap(), 0, lpszResponseBuffer);
- *lpdwCurrentDirectory = len;
- bSuccess = TRUE;
+ if (len >= *lpdwCurrentDirectory)
+ {
+ *lpdwCurrentDirectory = len + 1;
+ FTP_SetResponseError(ERROR_INTERNET_BAD_OPTION_LENGTH);
+ }
+ else
+ {
+ *lpdwCurrentDirectory = len;
+ memcpy(lpszCurrentDirectory, &lpszResponseBuffer[firstpos+1], len*sizeof(WCHAR));
+ lpszCurrentDirectory[len] = '\0';
+ bSuccess = TRUE;
+ }
+ HeapFree(GetProcessHeap(), 0, lpszResponseBuffer);
}
else
FTP_SetResponseError(nResCode);
More information about the wine-devel
mailing list