Skip to content

Bad free in assemble function #87524

Closed
Closed

Description

@alexhenrie
mannequin
BPO 43358
Nosy @markshannon, @alexhenrie
PRs
  • bpo-43358: Fix bad free in assemble function #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']

    Activity

    1. alexhenrie commented on Mar 2, 2021

      alexhenriemannequin
      MannequinAuthor

      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\>

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Mar 2, 2021
    3. markshannon commented on Mar 2, 2021

      @markshannon
      Member

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

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions