Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault in new PEG parser #85080

Closed
stestagg mannequin opened this issue Jun 7, 2020 · 6 comments
Closed

Segfault in new PEG parser #85080

stestagg mannequin opened this issue Jun 7, 2020 · 6 comments
Assignees
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@stestagg
Copy link
Mannequin

stestagg mannequin commented Jun 7, 2020

BPO 40903
Nosy @vstinner, @pablogsal, @miss-islington, @stestagg
PRs
  • bpo-40903: Handle multiple '=' in invalid assignment rules in the PEG parser #20697
  • [3.9] bpo-40903: Handle multiple '=' in invalid assignment rules in the PEG parser (GH-20697) #20704
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/pablogsal'
    closed_at = <Date 2020-06-08.10:04:06.100>
    created_at = <Date 2020-06-07.22:09:09.431>
    labels = ['interpreter-core', '3.10', 'type-crash']
    title = 'Segfault in new PEG parser'
    updated_at = <Date 2020-06-08.16:04:00.152>
    user = 'https://github.com/stestagg'

    bugs.python.org fields:

    activity = <Date 2020-06-08.16:04:00.152>
    actor = 'pablogsal'
    assignee = 'pablogsal'
    closed = True
    closed_date = <Date 2020-06-08.10:04:06.100>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2020-06-07.22:09:09.431>
    creator = 'stestagg'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40903
    keywords = ['patch']
    message_count = 6.0
    messages = ['370916', '370948', '370968', '371002', '371003', '371004']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'pablogsal', 'miss-islington', 'stestagg']
    pr_nums = ['20697', '20704']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue40903'
    versions = ['Python 3.10']

    @stestagg
    Copy link
    Mannequin Author

    stestagg mannequin commented Jun 7, 2020

    The input p=p= causes python 3.10 to crash.

    I bisected the change, and the behavior appears to have been introduced by 16ab070 (bpo-40334: Correctly identify invalid target in assignment errors (GH-20076) )

    Steps to reproduce:

    $ echo 'p=p=' | /path/to/python3.10
    === SIGSEGV (Address boundary error)

    Analysis:

    This code is an invalid assignment, and the parser tries to generate a useful message for this case (invalid_assignment_rule).

    However, the target of the assignment is a Name node.

    The invalid_assignment_rule function tries to identify the target of the assignment, to create a useful description for the error menssage by calling _PyPegen_get_invalid_target, passing in the Name Node.

    PyPegen_get_invalid_target returns NULL if the type is a Name type (pegen.c:2114).

    The result of this call is then passed unconditionally to _PyPegen_get_expr_name, which is expecting a statement, not NULL.

    Error happens here: pegen.c:164
    _PyPegen_get_expr_name(expr_ty e) is being called with e = 0x0

    @stestagg stestagg mannequin added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Jun 7, 2020
    @miss-islington
    Copy link
    Contributor

    New changeset 9f49590 by Pablo Galindo in branch 'master':
    bpo-40903: Handle multiple '=' in invalid assignment rules in the PEG parser (GH-20697)
    9f49590

    @miss-islington
    Copy link
    Contributor

    New changeset 8df4f39 by Miss Islington (bot) in branch '3.9':
    bpo-40903: Handle multiple '=' in invalid assignment rules in the PEG parser (GH-20697)
    8df4f39

    @vstinner
    Copy link
    Member

    vstinner commented Jun 8, 2020

    https://buildbot.python.org/all/#builders/765/builds/51

    The new test fails with the old parser:

    **********************************************************************
    File "/buildbot/buildarea/3.9.pablogsal-arch-x86_64.oldparser/build/Lib/test/test_syntax.py", line 66, in test.test_syntax
    Failed example:
        yield = 1
    Expected:
        Traceback (most recent call last):
        SyntaxError: assignment to yield expression not possible
    Got:
        Traceback (most recent call last):
          File "/buildbot/buildarea/3.9.pablogsal-arch-x86_64.oldparser/build/Lib/doctest.py", line 1336, in __run
            exec(compile(example.source, filename, "single",
          File "<doctest test.test_syntax[10]>", line 1
            yield = 1
                  ^
        SyntaxError: invalid syntax
    **********************************************************************
    1 items had failures:
       1 of 108 in test.test_syntax

    @vstinner
    Copy link
    Member

    vstinner commented Jun 8, 2020

    The new test fails with the old parser:

    Oh, it's already fixed by:
    2b33cc3

    @pablogsal
    Copy link
    Member

    The new test fails with the old parser:

    I fixed it this morning in #20717

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants