diff options
| author | Kirill Podoprigora <kirill.bast9@mail.ru> | 2024-10-29 18:20:40 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 18:20:40 (GMT) |
| commit | 515a5d3498b572057056f0eef143a29838978705 (patch) | |
| tree | 50dc568abb6287c94a19cd1548173e2211e9a73c /Python/Python-ast.c | |
| parent | bce9df97d5349e351666055bd797c99e55a1770a (diff) | |
| download | cpython-515a5d3498b572057056f0eef143a29838978705.zip cpython-515a5d3498b572057056f0eef143a29838978705.tar.gz cpython-515a5d3498b572057056f0eef143a29838978705.tar.bz2 | |
[3.12] gh-126105: Fix crash in `ast` module, when `._fields` is delet… (#126132)
[3.12] gh-126105: Fix crash in `ast` module, when `._fields` is deleted (GH-126115)
Previously, if the `ast.AST._fields` attribute was deleted, attempts to create a new `as`t node would crash due to the assumption that `_fields` always had a non-NULL value. Now it has been fixed by adding an extra check to ensure that `_fields` does not have a NULL value (this can happen when you manually remove `_fields` attribute).
(cherry picked from commit b2eaa75b176e07730215d76d8dce4d63fb493391)
Co-authored-by: sobolevn <mail@sobolevn.me>
Diffstat (limited to 'Python/Python-ast.c')
| -rw-r--r-- | Python/Python-ast.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index ecaff20..3d5aeff 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -863,14 +863,15 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) { + + fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields); + if (fields == NULL) { goto cleanup; } - if (fields) { - numfields = PySequence_Size(fields); - if (numfields == -1) { - goto cleanup; - } + + numfields = PySequence_Size(fields); + if (numfields == -1) { + goto cleanup; } res = 0; /* if no error occurs, this stays 0 to the end */ |
