This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: http.server.CGIHTTPRequestHandler doesn't check if a Python script is executable
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: orsenthil, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2011-06-08 23:47 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cgi.patch vstinner, 2011-06-09 00:42 review
Messages (4)
msg137930 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-06-08 23:47
CGIHTTPRequestHandler.run_cgi() only checks if the script processing the request is executable if the file is not a Python script, but later it uses os.execve(scriptfile, ...) if os has a fork() function.

Moreover, the executable() functions checks if os.stat(path).st_mode & 0o111 != 0: this test is wrong if st_mode & 0o111 != 0o111. For example, if the script has mode 0700 and is not owned by the current user, executable() returns True, whereas it should be False. os.access(filename, os.X_OK) should be used instead.

I found these issues while trying to understand the following failure on "FreeBSD 7.2 x86 3.x" buildbot:

[320/356/2] test_httpservers
Traceback (most recent call last):
  File "/usr/home/db3l/buildarea/3.x.bolen-freebsd7/build/Lib/http/server.py", line 1123, in run_cgi
OSError: [Errno 13] Permission denied
(...)

I don't understand how it happens because test_httpservers uses os.chmod(script, 0o777).
msg137934 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-06-09 00:42
cgi.patch: fix the test checking that the script file is executable.

The patch removes the executable() function. This function is not documented but is public. The patch can be easily modified to keep this function if needed.
msg138731 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-06-20 15:27
Both the changes suggested in the patch are fine. I think, it is okay to remove the executable function. It is undocumented as it is, and have not seen any standalone use of it. A note in NEWS can help.
msg138734 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-06-20 15:47
New changeset ecef74419d55 by Victor Stinner in branch 'default':
Close #12289: Fix "is executable?" test in the CGI server
http://hg.python.org/cpython/rev/ecef74419d55
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56498
2011-06-20 15:47:00python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg138734

resolution: fixed
stage: resolved
2011-06-20 15:27:19orsenthilsetnosy: + orsenthil
messages: + msg138731
2011-06-09 00:42:39vstinnersetfiles: + cgi.patch
keywords: + patch
messages: + msg137934
2011-06-08 23:47:27vstinnercreate