This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix error/crash in AST: syntaxerror in complex ifs
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: twouters Nosy List: collinwinter, loewis, nnorwitz, twouters
Priority: critical Keywords: patch

Created on 2007-01-23 14:02 by twouters, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ast_complexif.diff twouters, 2007-01-23 14:02
Messages (6)
msg51785 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2007-01-23 14:02
Fix a bug in Python/ast.c, where a particular syntaxerror in an 'if' with one or more 'elif's would be ignored or mishandled:

timberwolf:~/python/python/trunk > cat test2.py
def bug():
    if w:
        dir()=1
    elif v:
        pass

timberwolf:~/python/python/trunk > python2.4 test2.py
  File "test2.py", line 3
    dir()=1
SyntaxError: can't assign to function call

timberwolf:~/python/python/trunk > python2.5 test2.py
Exception exceptions.SyntaxError: ("can't assign to function call", 3) in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted

The actual problem is the lack of error checks on the return values of ast_for_expr() and ast_for_suite, in ast_for_if_stmt. Attached patch fixes.
msg51786 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-02-14 09:46
The patch looks fine to me, please apply (or let me know if you want me to apply it).

I think there are a few other places where return values of ast_for_ aren't checked:
- ast_for_listcomp, not checking ast_for_expr results
- ast_for_withexpr, not checking context_expr
msg51787 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-16 04:13
Updated to apply against SVN HEAD and incorporated the additional error checking Martin pointed out. Checked in as r54404 (trunk), r54405 (release25-maint).

Any objection to cleaning up ast.c's indentation? It's an ungodly mess.
msg51788 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-03-16 04:16
It would be great to clean up the indentation in ast.c.  I think I fixed it (at least made it consistent) in compile.c.  Probably symtable.c could use it too.  All the files that were new from the AST branch should be cleaned up and use the proper formatting we are using for 3k.  I don't remember exactly what it is, but I think it's 4 space indents, but possibly still using tabs.
msg51789 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-16 04:20
PEP 7's section on Py3k says 4-space indents, no tabs.
msg51790 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-03-16 12:35
I don't object to reformatting, if it's a single commit. It would be good if you could add Emacs magic at the end so the file keeps its formatting when edited with Emacs.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44496
2007-01-23 14:02:33twouterscreate