file name buffer in CDM_GETSPEC

ilejncs ilejncs at narod.ru
Thu Oct 13 02:06:49 CDT 2005


Hello!

Starting from NT (not sure about '95), Windows is capable to handle
CDM_GETSPEC with NULL as lParam. It is handy for calculating
file name length if actual content does not matter while
it is undocumented behavior.

I suggest memcpy file name in FILEDLG95_Handle_GetFileSpec 
if pointer is not zero only.

Besides this, MSDN clearly says passed buffer could be not large enough
for full file name. As far as I can see, WINE is fine for non-unicoded 
flavour here and I suggest fixing for unicoded as well.

Please, check me about "-1" thing in memcpy.
   
cvs diff -u filedlg.c (in directory C:\temp\wine\dlls\commdlg\)
Index: filedlg.c
===================================================================
RCS file: /home/wine/wine/dlls/commdlg/filedlg.c,v
retrieving revision 1.115
diff -u -r1.115 filedlg.c
--- filedlg.c	6 Oct 2005 11:38:45 -0000	1.115
+++ filedlg.c	13 Oct 2005 06:51:17 -0000
@@ -919,18 +919,29 @@
     TRACE("CDM_GETSPEC:\n");
 
     FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, ' ');
-    if( fodInfos->unicode )
+    if( fodInfos->unicode && buffer)
     {
         LPWSTR bufW = buffer;
-        memcpy( bufW, lpstrFileList, sizeof(WCHAR)*sizeUsed );
+        if (size >= sizeUsed)
+        {
+            memcpy( bufW, lpstrFileList, sizeof(WCHAR)*sizeUsed );
+        }
+        else
+        {
+            memcpy( bufW, lpstrFileList, sizeof(WCHAR)*(size-1) );
+            *(bufW + size -1) = 0;
+        }
     }
     else
     {
         LPSTR bufA = buffer;
         sizeUsed = WideCharToMultiByte( CP_ACP, 0, lpstrFileList, sizeUsed,
                                         NULL, 0, NULL, NULL);
-        WideCharToMultiByte(CP_ACP, 0, lpstrFileList, sizeUsed,
-                            bufA, size, NULL, NULL);
+        if( buffer )
+        {
+            WideCharToMultiByte(CP_ACP, 0, lpstrFileList, sizeUsed,
+                                bufA, size, NULL, NULL);
+        }
     }
     MemFree(lpstrFileList);




More information about the wine-patches mailing list