]> granicus.if.org Git - python/commitdiff
Close #12289: Fix "is executable?" test in the CGI server
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 20 Jun 2011 15:45:54 +0000 (17:45 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 20 Jun 2011 15:45:54 +0000 (17:45 +0200)
Use os.access(path, os.X_OK) instead of (os.stat(path).st_mode & 0o111 != 0),
and ignore the test on Windows.

Lib/http/server.py

index 1d193f8b2afbae1b4199aa275e09ddd13f7c92c0..e571418cc002e4b157e065705bf0a3cd07dd3029 100644 (file)
@@ -897,11 +897,7 @@ def nobody_uid():
 
 def executable(path):
     """Test for executable file."""
-    try:
-        st = os.stat(path)
-    except os.error:
-        return False
-    return st.st_mode & 0o111 != 0
+    return os.access(path, os.X_OK)
 
 
 class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
@@ -1015,7 +1011,7 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
                             scriptname)
             return
         ispy = self.is_python(scriptname)
-        if not ispy:
+        if self.have_fork or not ispy:
             if not self.is_executable(scriptfile):
                 self.send_error(403, "CGI script is not executable (%r)" %
                                 scriptname)