raspberrypi: SSLSocket: raise OSError when appropriate
Rather than returning the negative error value. This is intended to close #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 ```
This commit is contained in:
parent
3f66a0be83
commit
de9233f84a
@ -260,8 +260,8 @@ mp_uint_t common_hal_ssl_sslsocket_recv_into(ssl_sslsocket_obj_t *self, uint8_t
|
||||
// renegotation.
|
||||
ret = MP_EWOULDBLOCK;
|
||||
}
|
||||
DEBUG("returning [error case] %d\n", -ret);
|
||||
return -ret;
|
||||
DEBUG("raising errno [error case] %d\n", ret);
|
||||
mp_raise_OSError(ret);
|
||||
}
|
||||
|
||||
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
|
||||
// renegotation.
|
||||
ret = MP_EWOULDBLOCK;
|
||||
}
|
||||
DEBUG("returning [error case] %d\n", -ret);
|
||||
return -ret;
|
||||
DEBUG("raising errno [error case] %d\n", ret);
|
||||
mp_raise_OSError(ret);
|
||||
}
|
||||
|
||||
bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user