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

Benjamin Peterson webhook-mailer at python.org
Fri Aug 24 01:28:42 EDT 2018


https://github.com/python/cpython/commit/67dafd5c202cd529e209bf3f35e022ce766709eb
commit: 67dafd5c202cd529e209bf3f35e022ce766709eb
branch: 2.7
author: Benjamin Peterson <benjamin at python.org>
committer: GitHub <noreply at github.com>
date: 2018-08-23T22:28:39-07:00
summary:

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

(cherry picked from commit 704e2d374f88bca83339b95d559b0abce12dc6bd)

Co-authored-by: Christian Heimes <christian at cheimes.de>

files:
A Misc/NEWS.d/next/Core and Builtins/2018-08-23-21-32-27.bpo-18560.5q_c1C.rst
M Python/bltinmodule.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-08-23-21-32-27.bpo-18560.5q_c1C.rst b/Misc/NEWS.d/next/Core and Builtins/2018-08-23-21-32-27.bpo-18560.5q_c1C.rst
new file mode 100644
index 000000000000..4c1f06002228
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-08-23-21-32-27.bpo-18560.5q_c1C.rst	
@@ -0,0 +1 @@
+Fix potential NULL pointer dereference in sum().
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 21f6e66d82e1..4b819da8b399 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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);



More information about the Python-checkins mailing list