ID:               25361
 Updated by:       [EMAIL PROTECTED]
 Reported By:      sam at freepeers dot com
 Status:           Feedback
 Bug Type:         Program Execution
 Operating System: Windows 2000
 PHP Version:      4.3.2
 New Comment:

>From the cmd.exe /? help

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic
is
used to process quote (") characters:

1. If all of the following conditions are met, then quote characters
on the command line are preserved:

- no /S switch
- exactly two quote characters
- no special characters between the two quote characters,
where special is one of: &<>()@^|
- there are one or more whitespace characters between the
the two quote characters
- the string between the two quote characters is the name
of an executable file.

2. Otherwise, old behavior is to see if the first character is
a quote character and if so, strip the leading character and
remove the last quote character on the command line, preserving
any text after the last quote character.

My intent is to force the command line supplied by exec() et. al. to be
wrapped in a pair of quotes, thus forcing option 2 to be used.

For older windows (9x), using command.com, the help is ...

/C string       Carries out the command specified by string, and then
stops.

If 9x is not a concern (I'm getting it tested next week as I don't have
a 9x machine at hand), then the first patch could be used which only
wraps "" around NT+.




Previous Comments:
------------------------------------------------------------------------

[2007-08-03 09:10:28] [EMAIL PROTECTED]

Non volatile link (Sorry Pierre) :
http://rquadling.php1h.com/proc_open.c.diff2

------------------------------------------------------------------------

[2007-08-03 09:04:55] [EMAIL PROTECTED]

Index: proc_open.c
===================================================================
RCS file: /repository/php-src/ext/standard/proc_open.c,v
retrieving revision 1.57
diff -u -r1.57 proc_open.c
--- proc_open.c 28 May 2007 23:00:25 -0000      1.57
+++ proc_open.c 2 Aug 2007 09:30:57 -0000
@@ -740,7 +740,7 @@
        if (bypass_shell) {
                newprocok = CreateProcess(NULL, command, &security, &security, 
TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi);
        } else {
-               spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 
0x80000000
? COMSPEC_NT : COMSPEC_9X, command);
+               spprintf(&command_with_cmd, 0, "%s /c \"%s\"", GetVersion() <
0x80000000 ? COMSPEC_NT : COMSPEC_9X, command);
 
                newprocok = CreateProcess(NULL, command_with_cmd, &security,
&security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd,
&si, &pi);
 


------------------------------------------------------------------------

[2007-08-02 09:33:59] [EMAIL PROTECTED]

It may be that the /S is not required.

http://pastie.caboo.se/84306

------------------------------------------------------------------------

[2007-08-02 09:28:08] [EMAIL PROTECTED]

And thanks to Ashar Lohmar <[EMAIL PROTECTED]>, as he put me onto
this fix. He had a similar issue with wscript.

------------------------------------------------------------------------

[2007-08-02 09:22:46] [EMAIL PROTECTED]

For Windows NT+ (i.e. not win98-), this SEEMS to work.

cmd /s /c ""your long command" "another file""

Compare this against ...

cmd /c "your long command" "another file"

which doesn't work.

The /S option basically treats the rest of the string in quotes as a
command line.

This is slightly different behaviour.


%COMPSPEC% /S /C ""C:\Program Files\Internet Explorer\IEXPLORE.EXE"
"http://www.php.net"";


This is a patch to proc_open.c which I think should deal with the
issue. It may need to be optimized.

Index: proc_open.c
===================================================================
RCS file: /repository/php-src/ext/standard/proc_open.c,v
retrieving revision 1.57
diff -u -r1.57 proc_open.c
--- proc_open.c 28 May 2007 23:00:25 -0000      1.57
+++ proc_open.c 2 Aug 2007 09:21:02 -0000
@@ -740,7 +740,12 @@
        if (bypass_shell) {
                newprocok = CreateProcess(NULL, command, &security, &security, 
TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi);
        } else {
-               spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 
0x80000000
? COMSPEC_NT : COMSPEC_9X, command);
+               if (GetVersion() < 0x80000000) {
+                       /* Wrap command in quotes and use the /s parameter to 
pass quotes
to the command line. */
+                       spprintf(&command_with_cmd, 0, "%s /s /c \"%s\"", 
COMSPEC_NT,
command);
+               } else {
+                       spprintf(&command_with_cmd, 0, "%s /c %s", COMSPEC_9X, 
command);
+               }
 
                newprocok = CreateProcess(NULL, command_with_cmd, &security,
&security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd,
&si, &pi);
 
http://pastie.caboo.se/84303

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/25361

-- 
Edit this bug report at http://bugs.php.net/?id=25361&edit=1

Reply via email to