From 26b175844e7534fc8dfaaf54fac77703c686ec41 Mon Sep 17 00:00:00 2001 From: Noah Laptop Date: Mon, 11 Nov 2019 12:18:58 -0800 Subject: [PATCH] Fixed a bug causing a buffer overflow in the WiFi101 library --- src/SSLClient.cpp | 4 ++-- src/SSLClient.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SSLClient.cpp b/src/SSLClient.cpp index 783609a..87c4ea5 100644 --- a/src/SSLClient.cpp +++ b/src/SSLClient.cpp @@ -563,7 +563,7 @@ unsigned SSLClient::m_update_engine() { unsigned char * buf = br_ssl_engine_recvrec_buf(&m_sslctx.eng, &len); // do we have the record you're looking for? const auto avail = get_arduino_client().available(); - if (avail > 0 && static_cast(avail) >= len) { + if (avail > 0) { int mem = freeMemory(); #if defined(ARDUINO_ARCH_SAMD) // check for a stack overflow @@ -590,7 +590,7 @@ unsigned SSLClient::m_update_engine() { return 0; } // I suppose so! - int rlen = get_arduino_client().read(buf, len); + int rlen = get_arduino_client().read(buf, avail < len ? avail : len); if (rlen <= 0) { m_error("Error reading bytes from m_client. Write Error: ", func_name); m_error(get_arduino_client().getWriteError(), func_name); diff --git a/src/SSLClient.h b/src/SSLClient.h index 89954cb..1891f4f 100644 --- a/src/SSLClient.h +++ b/src/SSLClient.h @@ -407,7 +407,7 @@ private: //============================================ //= Data Members //============================================ - // create a copy of the client + // create a reference the client Client& m_client; // also store an array of SSLSessions, so we can resume communication with multiple websites std::vector m_sessions;