Skip to content

asserting that the tstate pointer is non-NULL using assert #122928

Closed as not planned

Description

@Wulian233

Bug report

Bug description:

https://github.com/python/cpython/blob/main/Python/pystate.c#L3016

To prevent dangling pointer issues, adding a check for NULL ensures that invalid pointers are not dereferenced

Linked PRs

Activity

  1. ZeroIntensity commented on Aug 12, 2024

    @ZeroIntensity
    Member

    As mentioned in the PR, a NULL check doesn't fix dangling pointers.

    With that being said, calling _PyThreadState_MustExit with an invalid thread state sounds like a bug, is there a specific case of this happening?

  2. neonene commented on Aug 13, 2024

    @neonene
    Contributor

    My understanding is that a problematic dangling pointer could be caused by the legacy non-isolated subinterpreter created with Py_NewInterpreter(), allowing daemon threads. Now that Python uses and recommends the new isolated subinterpreter, I do not think the concern is worth much consideration.

    See also #109794 (comment), #104341 (comment).

  3. picnixz commented on Aug 14, 2024

    @picnixz
    Member

    I'm wondering whether the issue should still mention dangling pointer since a dangling pointer is a valid pointer (hence non-null) pointing to invalid memory. It's more about asserting that the pointer is non-NULL using assert (namely, enforcing pre-conditions).

  4. neonene commented on Aug 15, 2024

    @neonene
    Contributor

    Please change the title, or make the PR belong to gh-109793. The current title is not good for closing here as "completed".

  5. changed the title [-]tstate might be a dangling pointer[/-] [+]asserting that the tstate pointer is non-NULL using assert[/+] on Aug 15, 2024
  6. vstinner commented on Sep 18, 2024

    @vstinner
    Member

    The change is not needed: #122929 (review)

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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions