How do I cause or create an invalid memory reference in Python on purpose?
This is a bit of a bar-bet. I'm told it can't be done. I don't believe that.
>>> import ctypes
>>> p = ctypes.POINTER(ctypes.c_int)(ctypes.c_int())
>>> p[100000000]
Segmentation fault
Create a module in C:
#include <Python.h>
static PyMethodDef SpamMethods[] =
{
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initspam(void)
{
(void)Py_InitModule("spam", SpamMethods);
int* invalidptr = NULL;
*invalidptr = 42;
}
And then from python:
import spam
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With