Close #12289: Fix "is executable?" test in the CGI server

Use os.access(path, os.X_OK) instead of (os.stat(path).st_mode & 0o111 != 0),
and ignore the test on Windows.
This commit is contained in:
Victor Stinner 2011-06-20 17:45:54 +02:00
parent 54e647f215
commit fb25ba9b07

View file

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