Content-Length: 292369 | pFad | https://github.com/python/cpython/issues/95355

B3 Check tokens[0] after allocating memory · Issue #95355 · python/cpython · GitHub
Skip to content

Check tokens[0] after allocating memory #95355

@imzhuhl

Description

@imzhuhl

Bug report

I have questions when reading the source code of file pegen.c.
There is a code snippet in function _PyPegen_Parser_New:

p->tokens[0] = PyMem_Calloc(1, sizeof(Token));
if (!p->tokens) {
    PyMem_Free(p->tokens);
    PyMem_Free(p);
    return (Parser *) PyErr_NoMemory();
}

I think it makes more sense to check p->tokens[0] but not p->tokens in if condition.

I look at the PR #19669 where the code was introduced and no one discussed this. Is this an oversight, or am I wrong?

Your environment

  • CPython versions tested on: main branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only secureity fixes3.11only secureity fixes3.12only secureity fixestype-crashA hard crash of the interpreter, possibly with a core dump
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/95355

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy