From ebf35229ccfe1d8377c7431d3b31d56ec9cab4c8 Mon Sep 17 00:00:00 2001 From: Johnathan York Date: Mon, 8 Feb 2021 23:46:22 -0600 Subject: [PATCH] extmod/modussl_mbedtls: Consider mbedtls buffer when poll()'ing. This commit fixes a bug where a poll() for read would not consider bytes available internally within the mbedtls_ssl's application data record read buffer. The bug would trigger if the caller's previous read() only retreived a portion of the bytes available, then called poll(). In spite of the wrapped socket being immediately readable, the poll() would incorrectly block (or timeout) because it was passing the poll ioctl down to the raw socket and waiting for additional encrypted data to arrive on the raw socket. The fix checks for bytes available via the mbedtls_ssl_get_bytes_avail() call before handing down to the raw socket. Signed-off-by: Johnathan York --- extmod/modussl_mbedtls.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index 1677dc6e1ca70..a8331a4112188 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -347,6 +347,14 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i mbedtls_ssl_config_free(&self->conf); mbedtls_ctr_drbg_free(&self->ctr_drbg); mbedtls_entropy_free(&self->entropy); + } else if (request == MP_STREAM_POLL) { + /* For POLL_RD, first check if ssl layer has bytes available... */ + if (arg & MP_STREAM_POLL_RD) { + if (mbedtls_ssl_get_bytes_avail(&self->ssl) > 0) { + return MP_STREAM_POLL_RD; + } + } + /* ...otherwise fall through to pass request to underlying socket */ } // Pass all requests down to the underlying socket return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy