[ros-diffs] [tfaber] 56587: [SHELL32] - Port CommandLineToArgvW fixes from Wine. Fixes crash in shell32:shlexec test.

tfaber at svn.reactos.org tfaber at svn.reactos.org
Mon May 14 19:26:43 UTC 2012


Author: tfaber
Date: Mon May 14 19:26:40 2012
New Revision: 56587

URL: http://svn.reactos.org/svn/reactos?rev=56587&view=rev
Log:
[SHELL32]
- Port CommandLineToArgvW fixes from Wine. Fixes crash in shell32:shlexec test.

Modified:
    trunk/reactos/dll/win32/shell32/shell32_main.cpp

Modified: trunk/reactos/dll/win32/shell32/shell32_main.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shell32_main.cpp?rev=56587&r1=56586&r2=56587&view=diff
==============================================================================
--- trunk/reactos/dll/win32/shell32/shell32_main.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/shell32_main.cpp [iso-8859-1] Mon May 14 19:26:40 2012
@@ -66,27 +66,34 @@
     LPWSTR cmdline;
     int in_quotes,bcount;
 
+    if(!numargs)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return NULL;
+    }
+
     if (*lpCmdline==0)
     {
         /* Return the path to the executable */
-        DWORD len, size=16;
-
-        argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size);
+        DWORD len, deslen=MAX_PATH, size;
+
+        size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
         for (;;)
         {
-            len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
+            if (!(argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size))) return NULL;
+            len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
             if (!len)
             {
                 LocalFree(argv);
                 return NULL;
             }
-            if (len < size) break;
-            size*=2;
-            argv = (LPWSTR *)LocalReAlloc(argv, size, 0);
+            if (len < deslen) break;
+            deslen*=2;
+            size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
+            LocalFree( argv );
         }
         argv[0]=(LPWSTR)(argv+1);
-        if (numargs)
-            *numargs=1;
+        *numargs=1;
 
         return argv;
     }
@@ -133,11 +140,9 @@
     /* Allocate in a single lump, the string array, and the strings that go with it.
      * This way the caller can make a single GlobalFree call to free both, as per MSDN.
      */
-    argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR));
-
+    argv=(LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR));
     if (!argv)
         return NULL;
-
     cmdline=(LPWSTR)(argv+argc);
     wcscpy(cmdline, lpCmdline);
 
@@ -203,8 +208,7 @@
         *d='\0';
         argv[argc++]=arg;
     }
-    if (numargs)
-        *numargs=argc;
+    *numargs=argc;
 
     return argv;
 }




More information about the Ros-diffs mailing list