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

Bad free in assemble function #87524

Closed
alexhenrie mannequin opened this issue Mar 2, 2021 · 2 comments
Closed

Bad free in assemble function #87524

alexhenrie mannequin opened this issue Mar 2, 2021 · 2 comments
Labels
3.10 interpreter-core type-crash

Comments

@alexhenrie
Copy link
Mannequin

@alexhenrie alexhenrie mannequin commented Mar 2, 2021

BPO 43358
Nosy @markshannon, @alexhenrie
PRs
  • #24697
  • 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 = None
    closed_at = None
    created_at = <Date 2021-03-02.01:38:32.270>
    labels = ['interpreter-core', '3.10', 'type-crash']
    title = 'Bad free in assemble function'
    updated_at = <Date 2021-03-02.10:20:36.017>
    user = 'https://github.com/alexhenrie'

    bugs.python.org fields:

    activity = <Date 2021-03-02.10:20:36.017>
    actor = 'Mark.Shannon'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2021-03-02.01:38:32.270>
    creator = 'alex.henrie'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43358
    keywords = ['patch']
    message_count = 2.0
    messages = ['387893', '387903']
    nosy_count = 2.0
    nosy_names = ['Mark.Shannon', 'alex.henrie']
    pr_nums = ['24697']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue43358'
    versions = ['Python 3.10']

    @alexhenrie
    Copy link
    Mannequin Author

    @alexhenrie alexhenrie mannequin commented Mar 2, 2021

    The assemble function in compile.c currently looks like this:

        static PyCodeObject *
        assemble(struct compiler *c, int addNone)
        {
            basicblock *b, *entryblock;
            struct assembler a;
            int j, nblocks;
            PyCodeObject *co = NULL;
            PyObject *consts = NULL;
        ...
    
            for (basicblock *b = c->u->u_blocks; b != NULL; b = b->b_list) {
                if (normalize_basic_block(b)) {
                    goto error;
                }
            }
    
            if (ensure_exits_have_lineno(c)) {
                goto error;
            }
        ...
    
         error:
            Py_XDECREF(consts);
            assemble_free(&a);
            return co;
        }

    If normalize_basic_block or ensure_exits_have_lineno fails, the function will attempt to free a.a_bytecode, which has not yet been initialized, possibly leading to a program crash.

    The problematic code was added by commit 5977a79 to fix bpo-42246.

    Defect identified by scan-build <https://clang-analyzer.llvm.org/scan-build.html\>

    @alexhenrie alexhenrie mannequin added 3.10 interpreter-core type-crash labels Mar 2, 2021
    @markshannon
    Copy link
    Member

    @markshannon markshannon commented Mar 2, 2021

    New changeset 503627f by Alex Henrie in branch 'master':
    bpo-43358: Fix bad free in assemble function (GH-24697)
    503627f

    @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 interpreter-core type-crash
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants