We use the built-in cpython as the scripting language in our application. We modify our sys.path at startup to make sure that we are not executing code from outside our application, but the user with sitecustomize.py in his PYTHONPATH causes the code to execute before we can fix sys.path and we believe that in their code a serious failure occurred (not an exception that site.py will cleverly handle and process).
I believe that the correct solution would be to simply clear the PYTHONPATH variable from the environment before we initialize python, but I cannot verify this properly because I cannot recreate the problem.
The easiest way I've found is to use ctypes to write to memory, for example:
import ctypes
p = (ctypes.c_char).from_address(0)
while True:
p[0] = 0
p = p + 1
But in Python 3.5, it does not allow me to write to c_char types, throwing an error "TypeError: object" c_char "does not support element assignment."
I tried several methods available at https://wiki.python.org/moin/CrashingPython, but to no avail.
Is there any reliable way to crash Python 3.5 from pure Python code?
source
share