From f8d403dd972a354fadc939d54dc0a1c45ffda327 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sun, 11 Dec 2005 20:12:40 +0000 Subject: SF #1377897, Bus error in ast If a line had multiple semi-colons and ended with a semi-colon, we would loop too many times and access a NULL node. Exit the loop early if there are no more children. --- Lib/test/test_grammar.py | 4 ++++ Python/ast.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 820fab5..aa76b44 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -276,6 +276,10 @@ check_syntax("lambda x: x = 2") ### simple_stmt: small_stmt (';' small_stmt)* [';'] print 'simple_stmt' x = 1; pass; del x +def foo(): + # verify statments that end with semi-colons + x = 1; pass; del x; +foo() ### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt # Tested below diff --git a/Python/ast.c b/Python/ast.c index 89ec217..04b2b3e 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2562,6 +2562,11 @@ ast_for_suite(struct compiling *c, const node *n) ch = CHILD(ch, 0); REQ(ch, simple_stmt); for (j = 0; j < NCH(ch); j += 2) { + /* statement terminates with a semi-colon ';' */ + if (NCH(CHILD(ch, j)) == 0) { + assert((j + 1) == NCH(ch)); + break; + } s = ast_for_stmt(c, CHILD(ch, j)); if (!s) goto error; -- cgit v0.12