Skip to content

Error handling bugs in ast.c #104482

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

Activity

  1. added a commit that references this issue on May 14, 2023
  2. added 3 commits that reference this issue on May 15, 2023
  3. added a commit that references this issue on May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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