Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e223439

Browse files
committed
Issue #19437: Fix ctypes, handle PyCData_GetContainer() and GetKeepedObjects()
failures
1 parent 588544d commit e223439

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,10 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
24052405
return 0;
24062406
}
24072407
ob = PyCData_GetContainer(target);
2408+
if (ob == NULL) {
2409+
Py_DECREF(keep);
2410+
return -1;
2411+
}
24082412
if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) {
24092413
Py_XDECREF(ob->b_objects);
24102414
ob->b_objects = keep; /* refcount consumed */
@@ -2791,6 +2795,9 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
27912795
/* XXX */;
27922796

27932797
value = GetKeepedObjects(src);
2798+
if (value == NULL)
2799+
return NULL;
2800+
27942801
Py_INCREF(value);
27952802
return value;
27962803
}
@@ -2814,6 +2821,9 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
28142821
*(void **)ptr = src->b_ptr;
28152822

28162823
keep = GetKeepedObjects(src);
2824+
if (keep == NULL)
2825+
return NULL;
2826+
28172827
/*
28182828
We are assigning an array object to a field which represents
28192829
a pointer. This has the same effect as converting an array
@@ -4810,6 +4820,9 @@ Pointer_set_contents(CDataObject *self, PyObject *value, void *closure)
48104820
return -1;
48114821

48124822
keep = GetKeepedObjects(dst);
4823+
if (keep == NULL)
4824+
return -1;
4825+
48134826
Py_INCREF(keep);
48144827
return KeepRef(self, 0, keep);
48154828
}
@@ -5216,9 +5229,14 @@ cast(void *ptr, PyObject *src, PyObject *ctype)
52165229
*/
52175230
if (CDataObject_Check(src)) {
52185231
CDataObject *obj = (CDataObject *)src;
5232+
CDataObject *container;
5233+
52195234
/* PyCData_GetContainer will initialize src.b_objects, we need
52205235
this so it can be shared */
5221-
PyCData_GetContainer(obj);
5236+
container = PyCData_GetContainer(obj);
5237+
if (container == NULL)
5238+
goto failed;
5239+
52225240
/* But we need a dictionary! */
52235241
if (obj->b_objects == Py_None) {
52245242
Py_DECREF(Py_None);

0 commit comments

Comments
 (0)