aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-02-22 05:34:06 -0800
committerGitHub <noreply@github.com>2020-02-22 05:34:06 -0800
commit0c1827e70c1c05ce1982a34380cea7d391904293 (patch)
treee253ef69b53e82c3838142390fcaf054dff0fc8e /Objects
parentbpo-39576: docs: set context for decimal arbitrary precision arithmetic (GH-1... (diff)
downloadcpython-0c1827e70c1c05ce1982a34380cea7d391904293.tar.gz
cpython-0c1827e70c1c05ce1982a34380cea7d391904293.tar.bz2
cpython-0c1827e70c1c05ce1982a34380cea7d391904293.zip
bpo-39382: Avoid dangling object use in abstract_issubclass() (GH-18530)
Hold reference of __bases__ tuple until tuple item is done with, because by dropping the reference the item may be destroyed. (cherry picked from commit 1c56f8ffad44478b4214a2bf8eb7cf51c28a347a) Co-authored-by: Yonatan Goldschmidt <yon.goldschmidt@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 77d09143aa0..bc1ebd930c0 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2336,9 +2336,16 @@ abstract_issubclass(PyObject *derived, PyObject *cls)
int r = 0;
while (1) {
- if (derived == cls)
+ if (derived == cls) {
+ Py_XDECREF(bases); /* See below comment */
return 1;
- bases = abstract_get_bases(derived);
+ }
+ /* Use XSETREF to drop bases reference *after* finishing with
+ derived; bases might be the only reference to it.
+ XSETREF is used instead of SETREF, because bases is NULL on the
+ first iteration of the loop.
+ */
+ Py_XSETREF(bases, abstract_get_bases(derived));
if (bases == NULL) {
if (PyErr_Occurred())
return -1;
@@ -2352,7 +2359,6 @@ abstract_issubclass(PyObject *derived, PyObject *cls)
/* Avoid recursivity in the single inheritance case */
if (n == 1) {
derived = PyTuple_GET_ITEM(bases, 0);
- Py_DECREF(bases);
continue;
}
for (i = 0; i < n; i++) {