michaelarmstrong / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

SSI relative include in subdirectories does not work for windows #328

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create an shtml page with a relative include, e.g., 
    <!--#include "file.ext" -->
2. put it in a subdirectory (not root), together with file.ext
3. open it: this will work in linux, but not in windows

What is the expected output? What do you see instead?
the content of file.ext is included in linux, but not in windows

What version of the product are you using? On what operating system?
current main line (3.2)

Please provide any additional information below.
this is due linux and http using / for directory separation while windows uses \
so windows has to deal with a mixture of its own \ and the / from http

to fix it: in function do_ssi_include:

replace
if ((p = strrchr(path, DIRSEP)) != NULL) {

by
if (((p = strrchr(path, '/')) != NULL) || ((p = strrchr(path, DIRSEP)) != 
NULL)) {

Actually there is a second place in handle_cgi_request with a similar line of 
code which might be the reason why the working directory of a cgi process in 
linux is the directory of the script while the working directory of the same 
script in windows is the web content root. Is this intentional?

Original issue reported on code.google.com by bel2...@gmail.com on 14 Mar 2012 at 10:08

GoogleCodeExporter commented 8 years ago
There is another more correct fix: uncomment line 1587 in mongoose.c

Windows by default handles correctly files like "C:\Web/file.html", but this 
breaks the  strrchr used in do_ssi_include to get the directory from the 
current SSI file.

Attached is a MingW-compiled mongoose "3.1.1" for Win32 with this bug fixed.

Original comment by socram8...@gmail.com on 15 Mar 2012 at 11:06

Attachments:

GoogleCodeExporter commented 8 years ago
Did you mean line 1588, function convert_uri_to_file_name of Version 
09127fc647dd?
//change_slashes_to_backslashes(buf);

Thank you, but I cannot use a prebuild executable since I need some more 
changes. However commenting out this line seems to solve the SSI issue. 
However, I wonder why it was commented out and what side effects this line may 
have. 

If it does not have side effects, it would of course be a nicer fix.

Original comment by bel2...@gmail.com on 15 Mar 2012 at 12:11

GoogleCodeExporter commented 8 years ago
This patch also changes the way the cgi interpreter ist called (the arguments 
of CreateProcessA). So the side effect is that cgi scripts in subdirectories do 
not work anymore for windows. 

I changed the Trace in spawn_process to
DEBUG_TRACE(("Running [%s] in [%s]", cmdline, dir));

1) With the line commented out I get
Running [Interpreter .\./Path/Script.cgi] in [.]

2) With the line active
Running [Interpreter .\Path\Script.cgi] in [.\Path]

the leading . is my content root (line "r ." in the .conf file)

For 2) the path to the cgi script is duplicated; 
so, the cgi interpreter searches for .\Path\Path\Script.cgi

To fix this, the path should not be added to the cmdline:

  (void) mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s%s",
                     interp, interp[0] == '\0' ? "" : " ", prog);

With these changes it works:
Running [Interpreter Script.cgi] in [.\Path]

I think this would fix the SSI relative include issue and unify the cgi working 
path for windows and linux.

Original comment by bel2...@gmail.com on 15 Mar 2012 at 3:39

GoogleCodeExporter commented 8 years ago
I've made suggested changes recently, and the aforementioned unification.
SSI works as intended. Minor remark: file=".." is considered by mongoose as 
relative to document root.
Paths relative to the current document should be specified as <!--#include 
"file.ext" -->

Original comment by valenok on 23 Sep 2012 at 12:55