Skip to content

Error handling bugs in ast.c #104482

Closed
@iritkatriel

Description

@iritkatriel

in validate_pattern, there are two places where in case of error we break out of a loop, but we also need to break out of the switch.

--- a/Python/ast.c
+++ b/Python/ast.c
@@ -580,7 +580,9 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
                     break;
                 }
             }
-
+            if (ret == 0) {
+                break;
+            }
             ret = validate_patterns(state, p->v.MatchMapping.patterns, /*star_ok=*/0);
             break;
         case MatchClass_kind:
@@ -620,6 +622,9 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
                 }
             }
 
+            if (ret == 0) {
+                break;
+            }
             if (!validate_patterns(state, p->v.MatchClass.patterns, /*star_ok=*/0)) {
                 ret = 0;
                 break;

If we don't do this we can end up calling _PyAST_Compile with an error set.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions