[issue1684] CGIHTTPServer does not chdir prior to executing the CGI script
New submission from Fazal Majid: The CGI specification does not specify the working directory the CGI is invoked in, but the usual behavior is to use the directory containing the script. CGIHTTPServer should either change working directory by default (see patch below), or offer a hook to be called before the exec() call to the CGI. *** /usr/local/lib/python2.4/CGIHTTPServer.py Tue Apr 4 11:13:23 2006 --- kCGIHTTPServer.py Fri Dec 21 13:31:40 2007 *** *** 227,232 --- 227,233 pass os.dup2(self.rfile.fileno(), 0) os.dup2(self.wfile.fileno(), 1) + os.chdir(os.path.dirname(scriptfile)) os.execve(scriptfile, args, os.environ) except: self.server.handle_error(self.request, self.client_address) -- components: Library (Lib) messages: 58955 nosy: majid severity: normal status: open title: CGIHTTPServer does not chdir prior to executing the CGI script type: behavior versions: Python 2.5 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1684> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1684] CGIHTTPServer does not chdir prior to executing the CGI script
Fazal Majid added the comment: There isn't any normative reference that I know of, in fact the default behavior is different on Unix and Windows. Apache 2.2 (and most certainly older versions as well) implements this in mod_cgi.c. The relevant lines: /* Transmute ourselves into the script. * NB only ISINDEX scripts get decoded arguments. */ if (((rc = apr_procattr_create(&procattr, p)) != APR_SUCCESS) || ((rc = apr_procattr_io_set(procattr, e_info->in_pipe, e_info->out_pipe, e_info->err_pipe)) != APR_SUCCESS) || ((rc = apr_procattr_dir_set(procattr, ap_make_dirstr_parent(r->pool, r->filename))) != APR_SUCCESS) || apr_procattr_dir_set sets the cwd for the child subprocess ap_make_dirstr_parent is equivalent to os.path.dirname. As the default behavior is system-dependent, it should not be hardcoded but some sort of hook should provided to allow implementing either the UNIX or Windows semantics. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1684> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1684] CGIHTTPServer does not chdir prior to executing the CGI script
Fazal Majid added the comment: MT-safety has nothing to do with this. The os.chdir() is invoked from the new child process that is forked just prior to calling execve() to run the CGI script, after which it exits. The parent CGIHTTPServer may be multithreaded, but invoking the CGI script is not a concurrent affair. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1684> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5809] "No such file or directory" with framework build under MacOS 10.4.11
Fazal Majid added the comment: I am experiencing the same problem with 2.6.2, whether using parallel make or not, but 2.6.1. builds just fine. -- nosy: +majid ___ Python tracker <http://bugs.python.org/issue5809> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1684] CGIHTTPServer does not chdir prior to executing the CGI script
Fazal Majid added the comment: The problem is that in the current implementation there is no hook to allow overriding any setup prior to exec, so the only way to produce the standard UNIX behavior assumed by many scripts is to copy-paste the code and patch it manually, which is very crude and defeats the whole idea of including it in the standard library. Part of the problem is that the CGI spec isn't properly documented. A great many early Internet standards were slapdashedly written up by Netscape on web sites that were dropped by AOL eventually. -- ___ Python tracker <http://bugs.python.org/issue1684> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1684] CGIHTTPServer does not chdir prior to executing the CGI script
Fazal Majid added the comment: Well, CGI/1.1 was formally documented by RFC 3875 in October 2004 (a full 11 years after CGI was introduced...). http://www.rfc-editor.org/rfc/rfc3875.txt The RFC is classified as "informative", but it's as close to a definitive spec for CGI as we will ever get. Section 7 described the system-specific implementation notes, and 7.2 specifies UNIX in particular: The current working directory The current working directory for the script SHOULD be set to the directory containing the script. This is also the specified behavior for AmugaDOS and EBCDIC POSIX systems. Oddly enough, the RFC editor did not find it worthwhile to specify the behavior on Windows... -- ___ Python tracker <http://bugs.python.org/issue1684> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com