Skip to content

Commit cbb4493

Browse files
fix: fix infinite recursion bug with the ESP32 when BearSSL wasn't ready to send
1 parent 1f9c1f9 commit cbb4493

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/SSLClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,19 @@ size_t SSLClient::write(const uint8_t *buf, size_t size) {
9696
if (m_debug >= DebugLevel::SSL_DUMP) Serial.write(buf, size);
9797
// check if the socket is still open and such
9898
if (!m_soft_connected(func_name) || !buf || !size) return 0;
99+
// wait until bearssl is ready to send
100+
if (m_run_until(BR_SSL_SENDAPP) < 0) {
101+
m_error("Failed while waiting for the engine to enter BR_SSL_SENDAPP", func_name);
102+
return 0;
103+
}
99104
// add to the bearssl io buffer, simply appending whatever we want to write
100105
size_t alen;
101106
unsigned char *br_buf = br_ssl_engine_sendapp_buf(&m_sslctx.eng, &alen);
102107
size_t cur_idx = 0;
108+
if (alen == 0) {
109+
m_error("BearSSL returned zero length buffer for sending, did an internal error occur?", func_name);
110+
return 0;
111+
}
103112
// while there are still elements to write
104113
while (cur_idx < size) {
105114
// if we're about to fill the buffer, we need to send the data and then wait

0 commit comments

Comments
 (0)