php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #50271
Patch proc_open_COMSPEC.patch revision 2010-03-26 13:35 UTC by rquadling@php.net
Patch TSRM_Win32_COMSPEC.patch revision 2010-03-26 13:05 UTC by rquadling@php.net

Patch proc_open_COMSPEC.patch for Program Execution Bug #50271

Patch version 2010-03-26 13:35 UTC

Return to Bug #50271 | Download this patch
Patch Revisions:

Developer: rquadling@php.net

Index: proc_open.c
===================================================================
--- proc_open.c	(revision 296837)
+++ proc_open.c	(working copy)
@@ -455,9 +455,6 @@
 #ifdef PHP_WIN32
 # define pipe(pair)		(CreatePipe(&pair[0], &pair[1], &security, 2048L) ? 0 : -1)
 
-# define COMSPEC_NT	"cmd.exe"
-# define COMSPEC_9X	"command.com"
-
 static inline HANDLE dup_handle(HANDLE src, BOOL inherit, BOOL closeorig)
 {
 	HANDLE copy, self = GetCurrentProcess();
@@ -513,7 +510,8 @@
 	BOOL newprocok;
 	SECURITY_ATTRIBUTES security;
 	DWORD dwCreateFlags = 0;
-	char *command_with_cmd;
+	char *command_with_cmd, *comspec, dummybuf;
+	int size;
 	UINT old_error_mode;
 #endif
 #ifdef NETWARE
@@ -792,11 +790,17 @@
 	if (bypass_shell) {
 		newprocok = CreateProcess(NULL, command, &security, &security, TRUE, dwCreateFlags, env.envp, cwd, &si, &pi);
 	} else {
-		spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command);
+		SetLastError(0);
+		size = GetEnvironmentVariableA("COMSPEC", &dummybuf, 0);
+		comspec = malloc(size);
+		GetEnvironmentVariableA("COMSPEC", comspec, size);
 
+		spprintf(&command_with_cmd, 0, "%s /c %s", comspec, command);
+
 		newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, dwCreateFlags, env.envp, cwd, &si, &pi);
 		
 		efree(command_with_cmd);
+		free(comspec);
 	}
 
 	if (suppress_errors) {
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 16:01:29 2024 UTC