[2.7] Issue GH-18560: Fix potential NULL pointer dereference in sum(). (GH-8892)

(cherry picked from commit 704e2d374f)

Co-authored-by: Christian Heimes <christian@cheimes.de>
This commit is contained in:
Benjamin Peterson 2018-08-23 22:28:39 -07:00 committed by GitHub
parent 45ee452751
commit 67dafd5c20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -0,0 +1 @@
Fix potential NULL pointer dereference in sum().

View File

@ -2363,6 +2363,11 @@ builtin_sum(PyObject *self, PyObject *args)
}
/* Either overflowed or is not an int. Restore real objects and process normally */
result = PyInt_FromLong(i_result);
if (result == NULL) {
Py_DECREF(item);
Py_DECREF(iter);
return NULL;
}
temp = PyNumber_Add(result, item);
Py_DECREF(result);
Py_DECREF(item);