From 8d865bf16748c729259503a3f35bba6792bcddd3 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 30 May 2022 17:21:32 +0100 Subject: [PATCH] fixup! gh-93351: Validate the position information when compiling AST nodes --- Python/ast.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/ast.c b/Python/ast.c index 55f7477eae3c96..0885fe7798fa5e 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -30,7 +30,7 @@ static int validate_pattern(struct validator *, pattern_ty, int); return 0; \ } \ if ((node->lineno < 0 && node->end_lineno != node->lineno) || \ - (node->col_offset < 0 && node->col_offset != node->end_col_offset)) { \ + (node->col_offset < 0 && node->col_offset != node->end_col_offset)) { \ PyErr_Format(PyExc_ValueError, \ "line %d-%d, column %d-%d is not a valid range", \ node->lineno, node->end_lineno, node->col_offset, node->end_col_offset); \ @@ -96,6 +96,7 @@ validate_args(struct validator *state, asdl_arg_seq *args) Py_ssize_t i; for (i = 0; i < asdl_seq_LEN(args); i++) { arg_ty arg = asdl_seq_GET(args, i); + VALIDATE_POSITIONS(arg); if (arg->annotation && !validate_expr(state, arg->annotation, Load)) return 0; } @@ -831,6 +832,7 @@ validate_stmt(struct validator *state, stmt_ty stmt) } for (i = 0; i < asdl_seq_LEN(stmt->v.Try.handlers); i++) { excepthandler_ty handler = asdl_seq_GET(stmt->v.Try.handlers, i); + VALIDATE_POSITIONS(handler); if ((handler->v.ExceptHandler.type && !validate_expr(state, handler->v.ExceptHandler.type, Load)) || !validate_body(state, handler->v.ExceptHandler.body, "ExceptHandler"))