file name buffer in CDM_GETSPEC (corrected)

ilejncs ilejncs at narod.ru
Thu Oct 13 06:11:43 CDT 2005


[
Sorry for previous patch. Ignore it please.
I polished the code just before sending and made a mistake.
]

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.

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 11:05:16 -0000
@@ -921,16 +921,30 @@
     FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, ' ');
     if( fodInfos->unicode )
     {
-        LPWSTR bufW = buffer;
-        memcpy( bufW, lpstrFileList, sizeof(WCHAR)*sizeUsed );
+        if( buffer )
+        {
+            LPWSTR bufW = buffer;
+            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