From 65aaef9750a3262293354dcf5759894cd53446e8 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 23 Jun 2026 11:25:08 +0000 Subject: [PATCH] Map WANT_WRITE from SSLSocket.recv_into() to SSLWantWriteError (F-3907) recv_into() shares read()'s error-mapping pattern and inherited the same omission: wolfSSL_read returning WOLFSSL_ERROR_WANT_WRITE (during a renegotiation needing a write) was reported as a generic SSLError instead of SSLWantWriteError, breaking non-blocking callers that distinguish readiness directions. Add the WANT_WRITE branch. --- tests/test_io_error_mapping.py | 15 +++++++++++++++ wolfssl/__init__.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/tests/test_io_error_mapping.py b/tests/test_io_error_mapping.py index 6ebd16d..eec6540 100644 --- a/tests/test_io_error_mapping.py +++ b/tests/test_io_error_mapping.py @@ -102,3 +102,18 @@ def test_read_want_read_still_raises_wantread(monkeypatch): sock = _make_socket() with pytest.raises(wolfssl.SSLWantReadError): sock.read(16) + + +def test_recv_into_want_write_raises_wantwrite(monkeypatch): + """F-3907: wolfSSL_read in recv_into returning WANT_WRITE.""" + _patch_lib(monkeypatch, -1, wolfssl._SSL_ERROR_WANT_WRITE) + sock = _make_socket() + with pytest.raises(wolfssl.SSLWantWriteError): + sock.recv_into(bytearray(16)) + + +def test_recv_into_want_read_still_raises_wantread(monkeypatch): + _patch_lib(monkeypatch, -1, wolfssl._SSL_ERROR_WANT_READ) + sock = _make_socket() + with pytest.raises(wolfssl.SSLWantReadError): + sock.recv_into(bytearray(16)) diff --git a/wolfssl/__init__.py b/wolfssl/__init__.py index d1c0807..5f06397 100644 --- a/wolfssl/__init__.py +++ b/wolfssl/__init__.py @@ -702,6 +702,9 @@ class SSLSocket(object): err = _lib.wolfSSL_get_error(self.native_object, 0) if err == _SSL_ERROR_WANT_READ: raise SSLWantReadError() + elif err == _SSL_ERROR_WANT_WRITE: + # wolfSSL_read can require a write first (e.g. renegotiation). + raise SSLWantWriteError() else: raise SSLError("wolfSSL_read error (%d)" % err)