Skip to content

Commit 95cf925

Browse files
Add OOM check and debug message in CertStore (#5820)
Fixes #5819
1 parent d507c79 commit 95cf925

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#include "CertStoreBearSSL.h"
2121
#include <memory>
2222

23+
24+
#ifdef DEBUG_ESP_SSL
25+
#define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR( "BSSL:" fmt), ## __VA_ARGS__)
26+
#else
27+
#define DEBUG_BSSL(...)
28+
#endif
29+
2330
namespace BearSSL {
2431

2532
extern "C" {
@@ -39,6 +46,11 @@ CertStore::CertInfo CertStore::_preprocessCert(uint32_t length, uint32_t offset,
3946
// Process it using SHA256, same as the hashed_dn
4047
br_x509_decoder_context *ctx = new br_x509_decoder_context;
4148
br_sha256_context *sha256 = new br_sha256_context;
49+
if (!ctx || !sha256) {
50+
DEBUG_BSSL("CertStore::_preprocessCert: OOM\n");
51+
return ci;
52+
}
53+
4254
br_sha256_init(sha256);
4355
br_x509_decoder_init(ctx, dn_append, sha256, nullptr, nullptr);
4456
br_x509_decoder_push(ctx, (const void*)raw, length);
@@ -172,6 +184,10 @@ const br_x509_trust_anchor *CertStore::findHashedTA(void *ctx, void *hashed_dn,
172184
cs->_data->close();
173185
cs->_x509 = new X509List(der, ci.length);
174186
free(der);
187+
if (!cs->_x509) {
188+
DEBUG_BSSL("CertStore::findHashedTA: OOM\n");
189+
return nullptr;
190+
}
175191

176192
br_x509_trust_anchor *ta = (br_x509_trust_anchor*)cs->_x509->getTrustAnchors();
177193
memcpy(ta->dn.data, ci.sha256, sizeof(ci.sha256));

0 commit comments

Comments
 (0)