]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.7] Fix a possible crash due to PyType_FromSpecWithBases() (GH-10304) (GH-13495)
authorPetr Viktorin <encukou@gmail.com>
Wed, 29 May 2019 03:35:33 +0000 (05:35 +0200)
committerNed Deily <nad@python.org>
Wed, 29 May 2019 03:35:33 +0000 (23:35 -0400)
If the PyObject_MALLOC() call failed in PyType_FromSpecWithBases(),
PyObject_Free() would be called on a static string in type_dealloc().
(cherry picked from commit 0613c1e481440aa8f54ba7f6056924c175fbcc13)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Objects/typeobject.c

index 3092e98f6b258d6903dd9973b74783f80bd812e1..7065ee518e5cda5c5f016bf61d7355c0feda3543 100644 (file)
@@ -2960,6 +2960,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
             size_t len = strlen(old_doc)+1;
             char *tp_doc = PyObject_MALLOC(len);
             if (tp_doc == NULL) {
+                type->tp_doc = NULL;
                 PyErr_NoMemory();
                 goto fail;
             }