msi: Pass the full custom action command to CreateProcess. (try 2)

Hans Leidekker hans at codeweavers.com
Tue Jun 14 03:45:10 CDT 2011


This version passes the app name to CreateProcess and calls SearchPath
to make sure it's fully qualified. The executable path is quoted in
the command string if it contains a space.

Fixes http://bugs.winehq.org/show_bug.cgi?id=27425
---
 dlls/msi/custom.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/dlls/msi/custom.c b/dlls/msi/custom.c
index 211bec0..4f6d0d4 100644
--- a/dlls/msi/custom.c
+++ b/dlls/msi/custom.c
@@ -768,14 +768,58 @@ static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
     return r;
 }
 
-static HANDLE execute_command( const WCHAR *exe, WCHAR *arg, const WCHAR *dir )
+static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
 {
+    static const WCHAR dotexeW[] = {'.','e','x','e',0};
     STARTUPINFOW si;
     PROCESS_INFORMATION info;
+    WCHAR *exe = NULL, *cmd = NULL, *p;
     BOOL ret;
 
+    if (app)
+    {
+        int len_arg = 0;
+        DWORD len_exe = SearchPathW( NULL, app, dotexeW, 0, NULL, NULL );
+
+        if (!len_exe)
+        {
+            WARN("can't find executable %u\n", GetLastError());
+            return INVALID_HANDLE_VALUE;
+        }
+        if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
+        len_exe = SearchPathW( NULL, app, dotexeW, len_exe, exe, NULL );
+
+        if (arg) len_arg = strlenW( arg );
+        if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
+        {
+            msi_free( exe );
+            return INVALID_HANDLE_VALUE;
+        }
+        p = cmd;
+        if (strchrW( exe, ' ' ))
+        {
+            *p++ = '\"';
+            memcpy( p, exe, len_exe * sizeof(WCHAR) );
+            p += len_exe;
+            *p++ = '\"';
+            *p = 0;
+        }
+        else
+        {
+            strcpyW( p, exe );
+            p += len_exe;
+        }
+        if (arg)
+        {
+            *p++ = ' ';
+            memcpy( p, arg, len_arg * sizeof(WCHAR) );
+            p[len_arg] = 0;
+        }
+    }
     memset( &si, 0, sizeof(STARTUPINFOW) );
-    ret = CreateProcessW( exe, arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
+    ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
+    msi_free( cmd );
+    msi_free( exe );
     if (!ret)
     {
         WARN("unable to execute command %u\n", GetLastError());
-- 
1.7.4.1







More information about the wine-patches mailing list