Skip to content

Harden --locals against trashed memory#194

Merged
godlygeek merged 1 commit intobloomberg:mainfrom
godlygeek:handle_trashed_locals
Aug 1, 2024
Merged

Harden --locals against trashed memory#194
godlygeek merged 1 commit intobloomberg:mainfrom
godlygeek:handle_trashed_locals

Conversation

@godlygeek
Copy link
Copy Markdown
Contributor

@godlygeek godlygeek commented Jul 31, 2024

When attempting to produce a repr for local variables, attempt to cope
better with trashed memory:

  • Use "<invalid object at 0x1234>" as the repr of a PyObject* pointing
    directly at invalid memory, or one whose ob_type points at invalid
    memory.
  • Use "<list object at 0x1234>" as, for instance, the repr of a list containing an
    invalid ob_items pointer. More generally, use this for any object
    where we can determine the type, but generating the repr according to
    that type's rules fails due to accessing unmapped memory.

Test this with some ctypes abuse.

@godlygeek godlygeek self-assigned this Jul 31, 2024
@godlygeek godlygeek marked this pull request as draft July 31, 2024 23:30
@godlygeek godlygeek force-pushed the handle_trashed_locals branch from 0c7a734 to db11510 Compare August 1, 2024 00:00
@godlygeek godlygeek force-pushed the handle_trashed_locals branch from db11510 to 6721256 Compare August 1, 2024 00:06
When attempting to produce a repr for local variables, attempt to cope
better with trashed memory:

- Use "<invalid object at 0x1234>" as the repr of a `PyObject*` pointing
  directly at invalid memory, or one whose `ob_type` points at invalid
  memory.
- Use "<list object at 0x1234>" as, for instance, the repr of a list containing an
  invalid `ob_items` pointer. More generally, use this for any object
  where we can determine the type, but generating the repr according to
  that type's rules fails due to accessing unmapped memory.

Test this with some ctypes abuse.

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
@godlygeek godlygeek force-pushed the handle_trashed_locals branch from 6721256 to 456f12b Compare August 1, 2024 00:07
@godlygeek godlygeek marked this pull request as ready for review August 1, 2024 00:18
Copy link
Copy Markdown
Collaborator

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but left a comment regarding the (possible) flakiness of the test

@godlygeek godlygeek merged commit 07524ca into bloomberg:main Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants