file name buffer in CDM_GETSPEC (corrected)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

file name buffer in CDM_GETSPEC (corrected)

ilejncs
[
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);