Skip to content

bltinmodule.c: lazy_import NULL deref without Python frame #151510

@aisk

Description

@aisk

Crash report

What happened?

Original gist: https://gist.github.com/devdanzin/cc84f43d7a5c774b47551060c061391f. A PR is on the way.

Summary

builtin___lazy_import___impl (line 321): When globals=NULL and PyEval_GetGlobals() returns NULL (no Python frame), PyDict_Check(globals) dereferences NULL → segfault. Reachable from embedded interpreters.

Fix

Add NULL check for globals after PyEval_GetGlobals().

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Output from running 'python -VV' on the command line:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-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