You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Paul Sutton <pa...@ukweb.com> on 1997/10/22 16:20:34 UTC

NT: spaces in paths

Um, the MSVC runtime is *correctly* handling quote-delimited arguments on
the command line (at least on NT). So

  apache -d "d:/program files/apache"

works fine, to start with. Then Apache spawns child processes. They have
argv's like this passed to spawn():

  argv[0] = apache
  argv[1] = -d
  argv[2] = d:/program files/apache
  argv[3] = NULL

So, no problem. But (and I can't believe this) when the child process
starts, it gets:

  argv[0] = apache
  argv[1] = -d
  argv[2] = d:/program
  argv[3] = files/apache

That is, WIN32 is *within the spawn()* function re-arranging the already
specified arguments based on whether the arguments contain spaces.  Does
it perhaps just printf all the argv[] options into a string. Umm, that's
what the info browser implies ("the combined lengths of the arguments,
plus the spaces inserted between the arguments, must not exceed 1024
bytes"). NOOOOO! This is madness. 

One work-around that seems to work is to quote all the arguments in
spawn()'s argv, like this:

  argv[0] = "apache"
  argv[1] = "-d"
  argv[2] = "d:/program files/apache"
  argv[3] = NULL

The patch (below) does this (this patch is not intended for use, just to
illustate the point). 

//pcs

--- /home/paul/remote-cvs/apachen/src/main/http_main.c	Tue Oct 21 08:17:40 1997
+++ ./http_main.c	Wed Oct 22 14:00:30 1997
@@ -4008,12 +4008,13 @@
     pass_argv[0] = argv[0];
     pass_argv[1] = "-c";
     pass_argv[2] = buf;
-    for (i = 1; i < argc; i++) {
-	pass_argv[i + 2] = argv[i];
+    for (i = 1; i < argc; i++) {
+        char *x = malloc(strlen(argv[i]+2));
+        sprintf(x, "\"%s\"", argv[i]);
+        pass_argv[i+2] = x;
     }
     pass_argv[argc + 2] = NULL;
 
-
     GetModuleFileName(NULL, mod, 200);
     rv = spawnv(_P_NOWAIT, mod, pass_argv);
 


Re: NT: spaces in paths

Posted by Dean Gaudet <dg...@arctic.org>.

On Thu, 23 Oct 1997, Ben Laurie wrote:

> Wonder what we have to do to make a path with a " in it work. Can't use
> a \, of course, coz that's just a path separator :-)

^ is the escape character under OS2, give that a whirl.

Dean


Re: NT: spaces in paths

Posted by Ben Laurie <be...@algroup.co.uk>.
Paul Sutton wrote:
> 
> Um, the MSVC runtime is *correctly* handling quote-delimited arguments on
> the command line (at least on NT). So
> 
>   apache -d "d:/program files/apache"
> 
> works fine, to start with. Then Apache spawns child processes. They have
> argv's like this passed to spawn():
> 
>   argv[0] = apache
>   argv[1] = -d
>   argv[2] = d:/program files/apache
>   argv[3] = NULL
> 
> So, no problem. But (and I can't believe this) when the child process
> starts, it gets:
> 
>   argv[0] = apache
>   argv[1] = -d
>   argv[2] = d:/program
>   argv[3] = files/apache
> 
> That is, WIN32 is *within the spawn()* function re-arranging the already
> specified arguments based on whether the arguments contain spaces.  Does
> it perhaps just printf all the argv[] options into a string. Umm, that's
> what the info browser implies ("the combined lengths of the arguments,
> plus the spaces inserted between the arguments, must not exceed 1024
> bytes"). NOOOOO! This is madness.

And they seriously think they can oust Unix with this kind of crap going
on? BTW, they almost certainly do have to do it this way because the
low-level functions that run things do just take one long string. Of
course, if they fix it, they'll have to say "the combined lengths of the
arguments, plus the spaces inserted between the arguments, plus two
times the number of arguments, must not exceed 1024 bytes", or, heaven
forfend, allocate a buffer of the right size.

I wonder if they check for overflows (NT security holes, here we come).

> 
> One work-around that seems to work is to quote all the arguments in
> spawn()'s argv, like this:
> 
>   argv[0] = "apache"
>   argv[1] = "-d"
>   argv[2] = "d:/program files/apache"
>   argv[3] = NULL
> 
> The patch (below) does this (this patch is not intended for use, just to
> illustate the point).

Wonder what we have to do to make a path with a " in it work. Can't use
a \, of course, coz that's just a path separator :-)

It wouldn't surprise me in the slightest if it just isn't possible.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache