Fixed a bug causing a buffer overflow in the WiFi101 library

This commit is contained in:
Noah Laptop 2019-11-11 12:18:58 -08:00
parent ab9a195124
commit 26b175844e
2 changed files with 3 additions and 3 deletions

View file

@ -563,7 +563,7 @@ unsigned SSLClient::m_update_engine() {
unsigned char * buf = br_ssl_engine_recvrec_buf(&m_sslctx.eng, &len); unsigned char * buf = br_ssl_engine_recvrec_buf(&m_sslctx.eng, &len);
// do we have the record you're looking for? // do we have the record you're looking for?
const auto avail = get_arduino_client().available(); const auto avail = get_arduino_client().available();
if (avail > 0 && static_cast<size_t>(avail) >= len) { if (avail > 0) {
int mem = freeMemory(); int mem = freeMemory();
#if defined(ARDUINO_ARCH_SAMD) #if defined(ARDUINO_ARCH_SAMD)
// check for a stack overflow // check for a stack overflow
@ -590,7 +590,7 @@ unsigned SSLClient::m_update_engine() {
return 0; return 0;
} }
// I suppose so! // 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) { if (rlen <= 0) {
m_error("Error reading bytes from m_client. Write Error: ", func_name); m_error("Error reading bytes from m_client. Write Error: ", func_name);
m_error(get_arduino_client().getWriteError(), func_name); m_error(get_arduino_client().getWriteError(), func_name);

View file

@ -407,7 +407,7 @@ private:
//============================================ //============================================
//= Data Members //= Data Members
//============================================ //============================================
// create a copy of the client // create a reference the client
Client& m_client; Client& m_client;
// also store an array of SSLSessions, so we can resume communication with multiple websites // also store an array of SSLSessions, so we can resume communication with multiple websites
std::vector<SSLSession> m_sessions; std::vector<SSLSession> m_sessions;