You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ctypes: NULL-dereference when using py_result restype #132417
When using ctypes with a function which returns a PyObject *, using restypectypes.py_object, and the function returns NULL, there's a Py_DECREF of the result, leading to a segfault:
The issue lies in GetResult: when O_get is the result handler, it calls Py_DECREF on the result value, even though that can be NULL. O_get handles the NULL case correctly, setting an exception if none was set, and passing on the NULL. Code after the Py_DECREF in GetResult also handles the NULL case correctly, so changing the Py_DECREF into a Py_XDECREF makes things work.
Pull request incoming.
CPython versions tested on:
CPython 3.10, CPython 3.13, CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Activity
pythonGH-132417: ctypes: Fix potential Py_DECREF(NULL) in py_object h…
pythonGH-132417: ctypes: Fix potential Py_DECREF(NULL) in py_object h…
pythonGH-132417: ctypes: Fix potential Py_DECREF(NULL) in py_object h…
pythonGH-132417: ctypes: Fix potential Py_DECREF(NULL) in py_object h…
GH-132417: ctypes: Fix potential `Py_DECREF(NULL)` when handling func…
pythonGH-132417: ctypes: Fix potential `Py_DECREF(NULL)` when handlin…
[3.13] GH-132417: ctypes: Fix potential `Py_DECREF(NULL)` when handli…
picnixz commentedon Apr 12, 2025
Thank you for the report & fix!