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

Skip to content

Commit 6a3db25

Browse files
committed
Issue #17828: _PyObject_GetDictPtr() may return NULL instead of a PyObject**
CID 1128792: Dereference null return value (NULL_RETURNS)
1 parent 507eabd commit 6a3db25

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Objects/exceptions.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,7 +2626,7 @@ _PyErr_TrySetFromCause(const char *format, ...)
26262626
PyObject* msg_prefix;
26272627
PyObject *exc, *val, *tb;
26282628
PyTypeObject *caught_type;
2629-
PyObject *instance_dict;
2629+
PyObject **dictptr;
26302630
PyObject *instance_args;
26312631
Py_ssize_t num_args;
26322632
PyObject *new_exc, *new_val, *new_tb;
@@ -2664,8 +2664,10 @@ _PyErr_TrySetFromCause(const char *format, ...)
26642664
}
26652665

26662666
/* Ensure the instance dict is also empty */
2667-
instance_dict = *_PyObject_GetDictPtr(val);
2668-
if (instance_dict != NULL && PyObject_Length(instance_dict) > 0) {
2667+
dictptr = _PyObject_GetDictPtr(val);
2668+
if ((dictptr != NULL) && (*dictptr != NULL) &&
2669+
(PyObject_Length(*dictptr) > 0)
2670+
) {
26692671
/* While we could potentially copy a non-empty instance dictionary
26702672
* to the replacement exception, for now we take the more
26712673
* conservative path of leaving exceptions with attributes set

0 commit comments

Comments
 (0)