Skip to content

Commit

Permalink
mingw: avoid spawning processes with a \\?\-prefixed executable
Browse files Browse the repository at this point in the history
The thing is: Executables on Windows may inspect their own path via
_pgmptr (see https://msdn.microsoft.com/en-us/library/tza1y5f7.aspx)
e.g. to figure out the location of related files.

Git, for example, needs to figure out where the libexec/git-core/
directory is with its supporting Unix shell and Perl scripts (and for
well-intentioned backwards-compatibility, even dashed forms of the
builtins).

These programs, however, may very well be unaware that they were
possibly called with the \\?\ prefix, and as a consequence, they may
very well be unable to handle it.

One prominent example is MSYS2's gdb (MINGW version). The symptom is:

	$ C:/msys64/mingw64/bin/gdb.exe --help
	Could not find platform independent libraries <prefix>
	Could not find platform dependent libraries <exec_prefix>
	Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
	ImportError: No module named site

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 7, 2017
1 parent 750c0a4 commit 7dc2796
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions win32/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ static intptr_t mingw_spawnve(int mode,
return -1;
}

/*
* It can be easily verified that _wspawnve() has no problems with a
* wcmd that has the \\?\ prefix and it may be a long path.
*
* However, some programs inspect their own absolute path, e.g. to
* infer the location of related files (think: git.exe and its exec
* path), and not all of these programs handle a \\?\ prefix well, e.g.
* MSYS2's gdb (MINGW version).
*
* So let's skip the prefix when possible (i.e. when the path fits
* within PATH_MAX minus some wiggling room).
*/
if (!wcsncmp(wcmd, L"\\\\?\\", 4) && wcslen(wcmd) < PATH_MAX)
wcmd += 4;

/*
* We cannot use _P_WAIT here because we need to kill spawned processes
* if we're killed, and _P_WAIT does not let us.
Expand Down

0 comments on commit 7dc2796

Please sign in to comment.