gh-109351: Fix crash when compiling AST with invalid NamedExpr (#109352)

This commit is contained in:
Jelle Zijlstra 2023-09-13 09:00:15 -07:00 committed by GitHub
parent d69805b38a
commit 79101edb03
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. */