diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2022-02-20 12:45:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-20 12:45:02 (GMT) |
commit | dde048819f3975bdf98b3e50ea9ef8ea25ecdb8e (patch) | |
tree | 1396741c3b970b9d9e7a6c475ec34619adb549a3 /Lib/asyncio/base_events.py | |
parent | ea3e0421b04a6081d604786a40e7f27ff854b428 (diff) | |
download | cpython-dde048819f3975bdf98b3e50ea9ef8ea25ecdb8e.zip cpython-dde048819f3975bdf98b3e50ea9ef8ea25ecdb8e.tar.gz cpython-dde048819f3975bdf98b3e50ea9ef8ea25ecdb8e.tar.bz2 |
[3.10] Raise TypeError if SSLSocket is passed to asyncio transport-based methods (GH-31442). (GH-31443)
(cherry picked from commit 1f9d4c93af380d00bf2e24bc5f5ce662d41504aa)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r-- | Lib/asyncio/base_events.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index f726e91..f51613d 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -202,6 +202,11 @@ else: pass +def _check_ssl_socket(sock): + if ssl is not None and isinstance(sock, ssl.SSLSocket): + raise TypeError("Socket cannot be of type SSLSocket") + + class _SendfileFallbackProtocol(protocols.Protocol): def __init__(self, transp): if not isinstance(transp, transports._FlowControlMixin): @@ -863,6 +868,7 @@ class BaseEventLoop(events.AbstractEventLoop): *, fallback=True): if self._debug and sock.gettimeout() != 0: raise ValueError("the socket must be non-blocking") + _check_ssl_socket(sock) self._check_sendfile_params(sock, file, offset, count) try: return await self._sock_sendfile_native(sock, file, @@ -1004,6 +1010,9 @@ class BaseEventLoop(events.AbstractEventLoop): raise ValueError( 'ssl_handshake_timeout is only meaningful with ssl') + if sock is not None: + _check_ssl_socket(sock) + if happy_eyeballs_delay is not None and interleave is None: # If using happy eyeballs, default to interleave addresses by family interleave = 1 @@ -1437,6 +1446,9 @@ class BaseEventLoop(events.AbstractEventLoop): raise ValueError( 'ssl_handshake_timeout is only meaningful with ssl') + if sock is not None: + _check_ssl_socket(sock) + if host is not None or port is not None: if sock is not None: raise ValueError( @@ -1531,6 +1543,9 @@ class BaseEventLoop(events.AbstractEventLoop): raise ValueError( 'ssl_handshake_timeout is only meaningful with ssl') + if sock is not None: + _check_ssl_socket(sock) + transport, protocol = await self._create_connection_transport( sock, protocol_factory, ssl, '', server_side=True, ssl_handshake_timeout=ssl_handshake_timeout) |