summaryrefslogtreecommitdiffstats
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-10-29 16:07:32 (GMT)
committerGitHub <noreply@github.com>2024-10-29 16:07:32 (GMT)
commit265bc19b84c34354a78abc57d47e96e717d1d5af (patch)
treea6363e2f9c702fe71747316c74c9c7840e6b0f31 /Python/Python-ast.c
parente2c188455f1ec2f4745722d94f5ada2e45173be4 (diff)
downloadcpython-265bc19b84c34354a78abc57d47e96e717d1d5af.zip
cpython-265bc19b84c34354a78abc57d47e96e717d1d5af.tar.gz
cpython-265bc19b84c34354a78abc57d47e96e717d1d5af.tar.bz2
[3.13] gh-126105: Fix crash in `ast` module, when `._fields` is deleted (GH-126115) (#126130)
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.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 0f04c43..08ac250 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -5078,19 +5078,17 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t i, numfields = 0;
int res = -1;
PyObject *key, *value, *fields, *attributes = NULL, *remaining_fields = NULL;
- if (PyObject_GetOptionalAttr((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;
- }
- remaining_fields = PySet_New(fields);
- }
- else {
- remaining_fields = PySet_New(NULL);
+
+ numfields = PySequence_Size(fields);
+ if (numfields == -1) {
+ goto cleanup;
}
+ remaining_fields = PySet_New(fields);
if (remaining_fields == NULL) {
goto cleanup;
}