Skip to content

ssl: a failed assignment or deletion of _SSLContext._msg_callback clears the callback #156166

Description

@serhiy-storchaka

Bug report

The setter of _ssl._SSLContext._msg_callback clears the current callback before validating the new value, so a rejected assignment or a deletion loses it.

>>> import ssl, _ssl
>>> ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
>>> descr = _ssl._SSLContext.__dict__['_msg_callback']
>>> descr.__set__(ctx, lambda *args: None)
>>> descr.__delete__(ctx)
Traceback (most recent call last):
  ...
TypeError: not a callable object
>>> print(descr.__get__(ctx))
None

Deleting the attribute should raise AttributeError, like for keylog_filename (gh-156099) and row_factory (gh-149738), and neither a failed deletion nor a failed assignment should change the value.

ssl.SSLContext wraps the attribute in a property which checks the value and has no deleter, so this is only reachable through the C type.

Linked PRs

Activity

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.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtopic-SSLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions