Skip to content

Commit 3f8cd46

Browse files
Fix BearSSL Server WDT (#5702)
Fixes #5701 WDTs and other issues with BearSSL::WiFiServerSecure The BSSL server was creating the client it returns on a connection in a way that caused the counter for the stack_thunk to get out of sync and cause it to be freed improperly by having the destructor be called one more time than the constructor. Looks like RVO. Rewrite the ::available() function in order to avoid this issue with help from @devyte.
1 parent 7d512c4 commit 3f8cd46

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: libraries/ESP8266WiFi/src/WiFiServerSecureBearSSL.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,30 @@ void WiFiServerSecure::setECCert(const X509List *chain, unsigned cert_issuer_key
7676
// Return a client if there's an available connection waiting. If one is returned,
7777
// then any validation (i.e. client cert checking) will have succeeded.
7878
WiFiClientSecure WiFiServerSecure::available(uint8_t* status) {
79+
WiFiClientSecure client;
80+
7981
(void) status; // Unused
8082
if (_unclaimed) {
8183
if (_sk && _sk->isRSA()) {
8284
WiFiClientSecure result(_unclaimed, _chain, _sk, _iobuf_in_size, _iobuf_out_size, _client_CA_ta);
8385
_unclaimed = _unclaimed->next();
8486
result.setNoDelay(_noDelay);
8587
DEBUGV("WS:av\r\n");
86-
return result;
88+
client = result;
8789
} else if (_sk && _sk->isEC()) {
8890
WiFiClientSecure result(_unclaimed, _chain, _cert_issuer_key_type, _sk, _iobuf_in_size, _iobuf_out_size, _client_CA_ta);
8991
_unclaimed = _unclaimed->next();
9092
result.setNoDelay(_noDelay);
9193
DEBUGV("WS:av\r\n");
92-
return result;
94+
client = result;
9395
} else {
9496
// No key was defined, so we can't actually accept and attempt accept() and SSL handshake.
9597
DEBUGV("WS:nokey\r\n");
9698
}
99+
} else {
100+
optimistic_yield(1000);
97101
}
98-
99-
// Something weird, return a no-op object
100-
optimistic_yield(1000);
101-
return WiFiClientSecure();
102+
return client;
102103
}
103104

104105

0 commit comments

Comments
 (0)