Skip to content

Fix incorrect function signatures in _testmultiphase (UBSan) #141553

Description

@ashm-dev

Bug report

Bug description:

UBSan reports errors such as:

modexport_create_string

Objects/moduleobject.c:546:13: runtime error: call to function modexport_create_string through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct PyModuleDef *)' /home/shamil/oss/cpython/main/./Modules/_testmultiphase.c:1066:5: note: modexport_create_string defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/moduleobject.c:546:13

Py_mod_state_free

Objects/moduleobject.c:1101:9: runtime error: call to function modexport_smoke_free through pointer to incorrect function type 'void (*)(void *)' /home/shamil/oss/cpython/main/./Modules/_testmultiphase.c:974: note: modexport_smoke_free defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/moduleobject.c:1101:9

The functions assigned to Py_mod_state_free and modexport_create_string use incorrect signatures, causing calls through mismatched function pointer types and leading to undefined behavior.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. mohsinm-dev commented on Nov 14, 2025

    @mohsinm-dev
    Contributor

    @ashm-dev I was working on the same fix.

  2. ashm-dev commented on Nov 14, 2025

    @ashm-dev
    ContributorAuthor

    @mohsinm-dev I already have a fix)

  3. picnixz commented on Nov 14, 2025

    @picnixz
    Member

    I am surprised that this was not caught when this was introduced.

  4. added a commit that references this issue on Nov 15, 2025
  5. picnixz commented on Nov 15, 2025

    @picnixz
    Member

    Thanks for the report & fix!

  6. added a commit that references this issue on Dec 6, 2025
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.15bugs and security fixesextension-modulesC modules in the Modules dirtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions