From 925ada52de7923bf2ef5ea064e58b463dc2e3d7d Mon Sep 17 00:00:00 2001 From: dyupina Date: Thu, 13 Mar 2025 17:44:16 +0300 Subject: [PATCH] fix possible NULL pointer dereference --- Modules/_ctypes/_ctypes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 96a057554960e2..d3b496887b5692 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2826,6 +2826,7 @@ PyCData_NewGetBuffer(PyObject *myself, Py_buffer *view, int flags) StgDictObject *item_dict = PyType_stgdict(item_type); if (view == NULL) return 0; + assert(dict); view->buf = self->b_ptr; view->obj = Py_NewRef(myself); @@ -2862,7 +2863,10 @@ PyCData_reduce(PyObject *myself, PyObject *args) { CDataObject *self = (CDataObject *)myself; - if (PyObject_stgdict(myself)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) { + StgDictObject *stgdict = PyObject_stgdict(myself); + assert(stgdict); + + if (stgdict->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) { PyErr_SetString(PyExc_ValueError, "ctypes objects containing pointers cannot be pickled"); return NULL;