Skip to content

Commit de9233f

Browse files
committed
raspberrypi: SSLSocket: raise OSError when appropriate
Rather than returning the negative error value. This is intended to close adafruit#7606, though I did not test with mqtt. Instead, I created a simple standalone test program: ```python import wifi, socketpool, ssl, time #wifi.radio.connect(<omitted>) import socketpool socket = socketpool.SocketPool(wifi.radio) ctx = ssl.create_default_context() b = bytearray(8) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sss = ctx.wrap_socket(s, server_hostname='example.com') sss.connect(('example.com', 443)) sss.setblocking(False) r = sss.recv_into(b) print(r, b) # prints 4294967285 which is -11 as unsigned sss.close() ``` Before the change, r was the out of range value 4294967285. After the change, the recv_into call raises OSError instead. This is comparable to the behavior on standard Python, though an SSLWantReadError is raised instead. The original (mis)behavior seems to match what was uncovered deep inside minimqtt by adding logging: ``` 370.578: DEBUG - PKT: _sock_exact_recv: recv_len = 4294967285 ```
1 parent 3f66a0b commit de9233f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ports/raspberrypi/common-hal/ssl/SSLSocket.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ mp_uint_t common_hal_ssl_sslsocket_recv_into(ssl_sslsocket_obj_t *self, uint8_t
260260
// renegotation.
261261
ret = MP_EWOULDBLOCK;
262262
}
263-
DEBUG("returning [error case] %d\n", -ret);
264-
return -ret;
263+
DEBUG("raising errno [error case] %d\n", ret);
264+
mp_raise_OSError(ret);
265265
}
266266

267267
mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t *buf, uint32_t len) {
@@ -279,8 +279,8 @@ mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t
279279
// renegotation.
280280
ret = MP_EWOULDBLOCK;
281281
}
282-
DEBUG("returning [error case] %d\n", -ret);
283-
return -ret;
282+
DEBUG("raising errno [error case] %d\n", ret);
283+
mp_raise_OSError(ret);
284284
}
285285

286286
bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {

0 commit comments

Comments
 (0)