Skip to content

Commit 0cef441

Browse files
committed
Added a NULL check for 'PyRecord::new_record' before calling
'PyTuple_SET_ITEM' in the 'PyRecord::getattro' function. Also 'PyRecord::new_record' will now raise a 'PyErr_NoMemory' exception when the call to 'tp_alloc' returns NULL.
1 parent cb675ab commit 0cef441

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

com/win32com/src/PyRecord.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ PyRecord *PyRecord::new_record(IRecordInfo *ri, PVOID data, PyRecordBuffer *owne
244244
char *buf = (char *)PyRecord::Type.tp_alloc(type, 0);
245245
if (buf == NULL) {
246246
delete owner;
247+
PyErr_NoMemory();
247248
return NULL;
248249
}
249250
return new (buf) PyRecord(ri, owner->data, owner);
@@ -641,7 +642,16 @@ PyObject *PyRecord::getattro(PyObject *self, PyObject *obname)
641642
// in the last parameter, i.e. 'sub_data == NULL'.
642643
this_data = (BYTE *)psa->pvData;
643644
for (i = 0; i < nelems; i++) {
644-
PyTuple_SET_ITEM(ret_tuple, i, PyRecord::new_record(sub, this_data, pyrec->owner));
645+
PyRecord *rec = PyRecord::new_record(sub, this_data, pyrec->owner);
646+
if (rec == NULL) {
647+
for (--i; i >= 0; i--) {
648+
Py_DECREF(PyTuple_GET_ITEM(ret_tuple, i));
649+
}
650+
Py_DECREF(ret_tuple);
651+
ret_tuple = NULL;
652+
goto array_end;
653+
}
654+
PyTuple_SET_ITEM(ret_tuple, i, rec);
645655
this_data += element_size;
646656
}
647657
array_end:

0 commit comments

Comments
 (0)