summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAlexey Izbyshev <izbyshev@ispras.ru>2022-05-06 04:01:15 (GMT)
committerGitHub <noreply@github.com>2022-05-06 04:01:15 (GMT)
commit85354ed78c0edb6d81a2bd53cabc85e547b8b26e (patch)
tree244e74e1f2aa63be2ffc02acf07f86268163fa68 /Objects
parentadcb6a6055c7fe6e02621f66945be237b42e945a (diff)
downloadcpython-85354ed78c0edb6d81a2bd53cabc85e547b8b26e.zip
cpython-85354ed78c0edb6d81a2bd53cabc85e547b8b26e.tar.gz
cpython-85354ed78c0edb6d81a2bd53cabc85e547b8b26e.tar.bz2
gh-92112: Fix crash triggered by an evil custom `mro()` (#92113)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 4afaf24..1bcfd9a 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -345,22 +345,26 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
Py_ssize_t i, n;
int custom = !Py_IS_TYPE(type, &PyType_Type);
int unbound;
- PyObject *mro_meth = NULL;
- PyObject *type_mro_meth = NULL;
if (custom) {
+ PyObject *mro_meth, *type_mro_meth;
mro_meth = lookup_maybe_method(
(PyObject *)type, &_Py_ID(mro), &unbound);
- if (mro_meth == NULL)
+ if (mro_meth == NULL) {
goto clear;
+ }
type_mro_meth = lookup_maybe_method(
(PyObject *)&PyType_Type, &_Py_ID(mro), &unbound);
- if (type_mro_meth == NULL)
+ if (type_mro_meth == NULL) {
+ Py_DECREF(mro_meth);
goto clear;
- if (mro_meth != type_mro_meth)
+ }
+ int custom_mro = (mro_meth != type_mro_meth);
+ Py_DECREF(mro_meth);
+ Py_DECREF(type_mro_meth);
+ if (custom_mro) {
goto clear;
- Py_XDECREF(mro_meth);
- Py_XDECREF(type_mro_meth);
+ }
}
n = PyTuple_GET_SIZE(bases);
for (i = 0; i < n; i++) {
@@ -373,8 +377,6 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
}
return;
clear:
- Py_XDECREF(mro_meth);
- Py_XDECREF(type_mro_meth);
type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
type->tp_version_tag = 0; /* 0 is not a valid version tag */
}