[3.12] gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352) (#109379)

gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352)
(cherry picked from commit 79101edb03)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-10-02 07:58:06 -07:00 committed by GitHub
parent 2fb39f73ed
commit 4b2ba3d0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View file

@ -381,6 +381,11 @@ validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
ret = validate_exprs(state, exp->v.Tuple.elts, ctx, 0);
break;
case NamedExpr_kind:
if (exp->v.NamedExpr.target->kind != Name_kind) {
PyErr_SetString(PyExc_TypeError,
"NamedExpr target must be a Name");
return 0;
}
ret = validate_expr(state, exp->v.NamedExpr.value, Load);
break;
/* This last case doesn't have any checking. */