Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 27f4961

Browse files
committed
SF patch 508730 CGIHTTPServer execfile should save cwd
UNTESTED!!! This simple two-line patch has been sitting on SF for more than 2 years. I'm guessing it's because nobody knows how to test it -- I sure don't. It doesn't look like you can get to this part of the code on Unixish or Windows systems, so the "how to test it?" puzzle has more than one part. OTOH, if this is dead code, it doesn't matter either if I just broke it <wink>.
1 parent 9dbf908 commit 27f4961

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Lib/CGIHTTPServer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def run_cgi(self):
120120
self.send_error(404, "No such CGI script (%r)" % scriptname)
121121
return
122122
if not os.path.isfile(scriptfile):
123-
self.send_error(403, "CGI script is not a plain file (%r)" %
123+
self.send_error(403, "CGI script is not a plain file (%r)" %
124124
scriptname)
125125
return
126126
ispy = self.is_python(scriptname)
@@ -273,6 +273,7 @@ def run_cgi(self):
273273
save_stdout = sys.stdout
274274
save_stderr = sys.stderr
275275
try:
276+
save_cwd = os.getcwd()
276277
try:
277278
sys.argv = [scriptfile]
278279
if '=' not in decoded_query:
@@ -285,6 +286,7 @@ def run_cgi(self):
285286
sys.stdin = save_stdin
286287
sys.stdout = save_stdout
287288
sys.stderr = save_stderr
289+
os.chdir(save_cwd)
288290
except SystemExit, sts:
289291
self.log_error("CGI script exit status %s", str(sts))
290292
else:

0 commit comments

Comments
 (0)