Skip to content

Commit

Permalink
Added a NULL check for 'PyRecord::new_record' before calling
Browse files Browse the repository at this point in the history
'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.
  • Loading branch information
geppi committed Jan 12, 2025
1 parent cb675ab commit 06105f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion com/win32com/src/PyRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ PyRecord *PyRecord::new_record(IRecordInfo *ri, PVOID data, PyRecordBuffer *owne
char *buf = (char *)PyRecord::Type.tp_alloc(type, 0);
if (buf == NULL) {
delete owner;
PyErr_NoMemory();
return NULL;
}
return new (buf) PyRecord(ri, owner->data, owner);
Expand Down Expand Up @@ -641,7 +642,13 @@ PyObject *PyRecord::getattro(PyObject *self, PyObject *obname)
// in the last parameter, i.e. 'sub_data == NULL'.
this_data = (BYTE *)psa->pvData;
for (i = 0; i < nelems; i++) {
PyTuple_SET_ITEM(ret_tuple, i, PyRecord::new_record(sub, this_data, pyrec->owner));
PyRecord *rec = PyRecord::new_record(sub, this_data, pyrec->owner);
if (rec == NULL) {
Py_DECREF(ret_tuple);
ret_tuple = NULL;
goto array_end;
}
PyTuple_SET_ITEM(ret_tuple, i, rec);
this_data += element_size;
}
array_end:
Expand Down

0 comments on commit 06105f2

Please sign in to comment.