Skip to content

Commit

Permalink
fixup! pythongh-93351: Validate the position information when compili…
Browse files Browse the repository at this point in the history
…ng AST nodes
  • Loading branch information
pablogsal committed May 30, 2022
1 parent dde7b64 commit 8d865bf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 8d865bf

Please sign in to comment.