]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105375: Improve error handling in compiler_enter_scope() (#105494)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Fri, 9 Jun 2023 16:55:53 +0000 (18:55 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2023 16:55:53 +0000 (18:55 +0200)
Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst [new file with mode: 0644]
Python/compile.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst b/Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst
new file mode 100644 (file)
index 0000000..b4d3a1a
--- /dev/null
@@ -0,0 +1 @@
+Fix bug in the compiler where an exception could end up being overwritten.
index 32431728422765266296f9e254c9eeceb2427e63..e3a76236f5723a7fd14b133aba00fec361073fe6 100644 (file)
@@ -1228,8 +1228,12 @@ compiler_enter_scope(struct compiler *c, identifier name,
     }
     u->u_metadata.u_name = Py_NewRef(name);
     u->u_metadata.u_varnames = list2dict(u->u_ste->ste_varnames);
+    if (!u->u_metadata.u_varnames) {
+        compiler_unit_free(u);
+        return ERROR;
+    }
     u->u_metadata.u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, DEF_COMP_CELL, 0);
-    if (!u->u_metadata.u_varnames || !u->u_metadata.u_cellvars) {
+    if (!u->u_metadata.u_cellvars) {
         compiler_unit_free(u);
         return ERROR;
     }