Skip to content

Conversation

neonene
Copy link
Contributor

@neonene neonene commented May 3, 2024

Debug build on Windows (and CI: 7bbce38):

>_testembed_d test_repeated_init_exec "import datetime"
--- Loop #1 ---
--- Loop #2 ---
Assertion failed: PyUnicode_CheckExact(ep_key), file C:\a\Objects\dictobject.c, line 1119

At the Loop #2, the static types are carried over in the _datetime module, but their tp_dict no longer has valid keys, since all interned strings (keys) are freed after _PyUnicode_ClearInterned() in unicodeobject.c is invoked.

To check a key without a crash, the following strings need to be statically allocated:

  • The names in PyMemberDef array
  • The names in PyMethodDef array
  • The names in PyGetSetDef array
  • The key parameters of the PyDict_SetItemString(tp_dict, key, value) calls.

This patch includes the names that are already statically allocated (e.g. getset names).


@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label May 3, 2024
@neonene neonene changed the title datetime: Fix use-after-free on embedded CPython gh-113055: datetime: Fix use-after-free on embedded CPython May 3, 2024
@neonene neonene marked this pull request as ready for review May 3, 2024 02:24
@neonene neonene requested review from pganssle and abalkin as code owners May 3, 2024 02:24
@neonene neonene changed the title gh-113055: datetime: Fix use-after-free on embedded CPython gh-118608: datetime: Fix use-after-free on embedded CPython May 5, 2024
@neonene neonene marked this pull request as draft May 5, 2024 20:04
@neonene neonene closed this May 23, 2024
@neonene neonene deleted the statickey branch May 23, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant