Rob Shearman : shell32: Don' t use the working directory passed into ShellExecute* functions if it isn' t valid.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Aug 31 14:01:22 CDT 2007


Module: wine
Branch: master
Commit: 94074ad31eed9c5d8bcbc5155bea124d39f85f2f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=94074ad31eed9c5d8bcbc5155bea124d39f85f2f

Author: Rob Shearman <rob at codeweavers.com>
Date:   Fri Aug 31 15:41:36 2007 +0100

shell32: Don't use the working directory passed into ShellExecute* functions if it isn't valid.

---

 dlls/shell32/shlexec.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c
index 3e2f623..69608df 100644
--- a/dlls/shell32/shlexec.c
+++ b/dlls/shell32/shlexec.c
@@ -306,14 +306,25 @@ static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
     UINT gcdret = 0;
     WCHAR curdir[MAX_PATH];
     DWORD dwCreationFlags;
+    const WCHAR *lpDirectory = NULL;
 
     TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
+
+    /* make sure we don't fail the CreateProcess if the calling app passes in
+     * a bad working directory */
+    if (psei->lpDirectory && psei->lpDirectory[0])
+    {
+        DWORD attr = GetFileAttributesW(psei->lpDirectory);
+        if (attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY)
+            lpDirectory = psei->lpDirectory;
+    }
+
     /* ShellExecute specifies the command from psei->lpDirectory
      * if present. Not from the current dir as CreateProcess does */
-    if( psei->lpDirectory && psei->lpDirectory[0] )
+    if( lpDirectory )
         if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
-            if( !SetCurrentDirectoryW( psei->lpDirectory))
-                ERR("cannot set directory %s\n", debugstr_w(psei->lpDirectory));
+            if( !SetCurrentDirectoryW( lpDirectory))
+                ERR("cannot set directory %s\n", debugstr_w(lpDirectory));
     ZeroMemory(&startup,sizeof(STARTUPINFOW));
     startup.cb = sizeof(STARTUPINFOW);
     startup.dwFlags = STARTF_USESHOWWINDOW;
@@ -322,8 +333,7 @@ static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
     if (psei->fMask & SEE_MASK_NO_CONSOLE)
         dwCreationFlags |= CREATE_NEW_CONSOLE;
     if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env,
-                       psei->lpDirectory && *psei->lpDirectory ? psei->lpDirectory : NULL,
-                       &startup, &info))
+                       lpDirectory, &startup, &info))
     {
         /* Give 30 seconds to the app to come up, if desired. Probably only needed
            when starting app immediately before making a DDE connection. */




More information about the wine-cvs mailing list