Issue #22636: avoid using a shell in the ctypes.util module
authorMartin Panter <vadmium+py@gmail.com>
Tue, 14 Jun 2016 01:27:11 +0000 (01:27 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Tue, 14 Jun 2016 01:27:11 +0000 (01:27 +0000)
commitbfb15ab71165ccdf65ed1243e80e7e293999f034
treee8b23233d40f4043e6d32e81406cb66c16d4a853
parentf00c49df10f04bf3b40c7d91efb8204068524d8f
Issue #22636: avoid using a shell in the ctypes.util module

Replace os.popen() with subprocess.Popen. Based on patch by Victor Stinner.

If the "gcc", "cc" or "objdump" command is not available, the code was
supposed to raise an OSError exception. But there was a bug in the code. The
shell code returns the exit code 10 if the required command is missing, and the
code tries to check for the status 10. The problem is that os.popen() doesn't
return the exit code directly, but a status which should be processed by
os.WIFEXITED() and os.WEXITSTATUS(). In practice, the exception was never
raised. The OSError exception was not documented and ctypes.util.find_library()
is expected to return None if the library is not found.
Lib/ctypes/test/test_find.py
Lib/ctypes/util.py
Misc/NEWS