Skip to content

Ensure that HMAC objects are properly initialized #155843

Description

@picnixz

Bug report

Bug description:

This affects the following situations:

  • _hmac.new() frees an uninitialized HACL pointer when the key exceeds UINT32_MAX
  • _hmac_HMAC_copy_impl runs HASHLIB_INIT_MUTEX(copy) after the fallible hmac_copy_state

The solution is simply to always entirely initialize the HMAC object before working with it. We also change the usage of PyObject_New to tp->tp_alloc directly so that we only alter fields for which the 0-value would not be suitable.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions