mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
replace new
by new (std::nothrow)
, remove arduino_new
This commit is contained in:
@ -145,7 +145,7 @@ void setup() {
|
||||
return; // Can't connect to anything w/o certs!
|
||||
}
|
||||
|
||||
BearSSL::WiFiClientSecure *bear = new BearSSL::WiFiClientSecure();
|
||||
BearSSL::WiFiClientSecure *bear = new (std::nothrow) BearSSL::WiFiClientSecure();
|
||||
// Integrate the cert store with this connection
|
||||
bear->setCertStore(&certStore);
|
||||
Serial.printf("Attempting to fetch https://github.com/...\n");
|
||||
@ -164,7 +164,7 @@ void loop() {
|
||||
site.replace(String("\n"), emptyString);
|
||||
Serial.printf("https://%s/\n", site.c_str());
|
||||
|
||||
BearSSL::WiFiClientSecure *bear = new BearSSL::WiFiClientSecure();
|
||||
BearSSL::WiFiClientSecure *bear = new (std::nothrow) BearSSL::WiFiClientSecure();
|
||||
// Integrate the cert store with this connection
|
||||
bear->setCertStore(&certStore);
|
||||
fetchURL(bear, site.c_str(), 443, "/");
|
||||
|
@ -161,8 +161,8 @@ void setup() {
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Attach the server private cert/key combo
|
||||
BearSSL::X509List *serverCertList = new BearSSL::X509List(server_cert);
|
||||
BearSSL::PrivateKey *serverPrivKey = new BearSSL::PrivateKey(server_private_key);
|
||||
BearSSL::X509List *serverCertList = new (std::nothrow) BearSSL::X509List(server_cert);
|
||||
BearSSL::PrivateKey *serverPrivKey = new (std::nothrow) BearSSL::PrivateKey(server_private_key);
|
||||
#ifndef USE_EC
|
||||
server.setRSACert(serverCertList, serverPrivKey);
|
||||
#else
|
||||
|
@ -202,12 +202,12 @@ void setup() {
|
||||
setClock(); // Required for X.509 validation
|
||||
|
||||
// Attach the server private cert/key combo
|
||||
BearSSL::X509List *serverCertList = new BearSSL::X509List(server_cert);
|
||||
BearSSL::PrivateKey *serverPrivKey = new BearSSL::PrivateKey(server_private_key);
|
||||
BearSSL::X509List *serverCertList = new (std::nothrow) BearSSL::X509List(server_cert);
|
||||
BearSSL::PrivateKey *serverPrivKey = new (std::nothrow) BearSSL::PrivateKey(server_private_key);
|
||||
server.setRSACert(serverCertList, serverPrivKey);
|
||||
|
||||
// Require a certificate validated by the trusted CA
|
||||
BearSSL::X509List *serverTrustedCA = new BearSSL::X509List(ca_cert);
|
||||
BearSSL::X509List *serverTrustedCA = new (std::nothrow) BearSSL::X509List(ca_cert);
|
||||
server.setClientTrustAnchor(serverTrustedCA);
|
||||
|
||||
// Actually start accepting connections
|
||||
|
@ -85,7 +85,7 @@ void setup() {
|
||||
Serial.swap();
|
||||
// Hardware serial is now on RX:GPIO13 TX:GPIO15
|
||||
// use SoftwareSerial on regular RX(3)/TX(1) for logging
|
||||
logger = new SoftwareSerial(3, 1);
|
||||
logger = new (std::nothrow) SoftwareSerial(3, 1);
|
||||
logger->begin(BAUD_LOGGER);
|
||||
logger->enableIntTx(false);
|
||||
logger->println("\n\nUsing SoftwareSerial for logging");
|
||||
|
@ -109,7 +109,7 @@ namespace brssl {
|
||||
}
|
||||
|
||||
static bool certificate_to_trust_anchor_inner(br_x509_trust_anchor *ta, const br_x509_certificate *xc) {
|
||||
std::unique_ptr<br_x509_decoder_context> dc(new br_x509_decoder_context); // auto-delete on exit
|
||||
std::unique_ptr<br_x509_decoder_context> dc(new (std::nothrow) br_x509_decoder_context); // auto-delete on exit
|
||||
std::vector<uint8_t> vdn;
|
||||
br_x509_pkey *pk;
|
||||
|
||||
@ -244,7 +244,7 @@ namespace brssl {
|
||||
// blobs may be returned.
|
||||
pem_object *decode_pem(const void *src, size_t len, size_t *num) {
|
||||
std::vector<pem_object> pem_list;
|
||||
std::unique_ptr<br_pem_decoder_context> pc(new br_pem_decoder_context); // auto-delete on exit
|
||||
std::unique_ptr<br_pem_decoder_context> pc(new (std::nothrow) br_pem_decoder_context); // auto-delete on exit
|
||||
if (!pc.get()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -405,7 +405,7 @@ namespace brssl {
|
||||
}
|
||||
|
||||
static public_key *decode_public_key(const unsigned char *buff, size_t len) {
|
||||
std::unique_ptr<br_pkey_decoder_context> dc(new br_pkey_decoder_context); // auto-delete on exit
|
||||
std::unique_ptr<br_pkey_decoder_context> dc(new (std::nothrow) br_pkey_decoder_context); // auto-delete on exit
|
||||
if (!dc.get()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -477,7 +477,7 @@ namespace brssl {
|
||||
}
|
||||
|
||||
static private_key *decode_private_key(const unsigned char *buff, size_t len) {
|
||||
std::unique_ptr<br_skey_decoder_context> dc(new br_skey_decoder_context); // auto-delete on exit
|
||||
std::unique_ptr<br_skey_decoder_context> dc(new (std::nothrow) br_skey_decoder_context); // auto-delete on exit
|
||||
if (!dc.get()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -50,9 +50,13 @@ CertStore::CertInfo CertStore::_preprocessCert(uint32_t length, uint32_t offset,
|
||||
memset(&ci, 0, sizeof(ci));
|
||||
|
||||
// Process it using SHA256, same as the hashed_dn
|
||||
br_x509_decoder_context *ctx = new br_x509_decoder_context;
|
||||
br_sha256_context *sha256 = new br_sha256_context;
|
||||
br_x509_decoder_context *ctx = new (std::nothrow) br_x509_decoder_context;
|
||||
br_sha256_context *sha256 = new (std::nothrow) br_sha256_context;
|
||||
if (!ctx || !sha256) {
|
||||
if (ctx)
|
||||
delete ctx;
|
||||
if (sha256)
|
||||
delete sha256;
|
||||
DEBUG_BSSL("CertStore::_preprocessCert: OOM\n");
|
||||
return ci;
|
||||
}
|
||||
@ -202,7 +206,7 @@ const br_x509_trust_anchor *CertStore::findHashedTA(void *ctx, void *hashed_dn,
|
||||
return nullptr;
|
||||
}
|
||||
data.close();
|
||||
cs->_x509 = new X509List(der, ci.length);
|
||||
cs->_x509 = new (std::nothrow) X509List(der, ci.length);
|
||||
free(der);
|
||||
if (!cs->_x509) {
|
||||
DEBUG_BSSL("CertStore::findHashedTA: OOM\n");
|
||||
|
@ -308,7 +308,10 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {
|
||||
if(i == 0) {
|
||||
ESP8266WiFiScanClass::_scanResult = 0;
|
||||
} else {
|
||||
bss_info* copied_info = new bss_info[i];
|
||||
bss_info* copied_info = new (std::nothrow) bss_info[i];
|
||||
if (copied_info == nullptr) {
|
||||
return;
|
||||
}
|
||||
i = 0;
|
||||
for(bss_info* it = head; it; it = STAILQ_NEXT(it, next), ++i) {
|
||||
memcpy(copied_info + i, it, sizeof(bss_info));
|
||||
|
@ -153,7 +153,10 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
|
||||
pcb->local_port = _localPort++;
|
||||
}
|
||||
|
||||
_client = new ClientContext(pcb, nullptr, nullptr);
|
||||
_client = new (std::nothrow) ClientContext(pcb, nullptr, nullptr);
|
||||
if (_client == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
_client->ref();
|
||||
_client->setTimeout(_timeout);
|
||||
int res = _client->connect(ip, port);
|
||||
|
@ -977,7 +977,7 @@ extern "C" {
|
||||
// Set custom list of ciphers
|
||||
bool WiFiClientSecure::setCiphers(const uint16_t *cipherAry, int cipherCount) {
|
||||
_cipher_list = nullptr;
|
||||
_cipher_list = std::shared_ptr<uint16_t>(new uint16_t[cipherCount], std::default_delete<uint16_t[]>());
|
||||
_cipher_list = std::shared_ptr<uint16_t>(new (std::nothrow) uint16_t[cipherCount], std::default_delete<uint16_t[]>());
|
||||
if (!_cipher_list.get()) {
|
||||
DEBUG_BSSL("setCiphers: list empty\n");
|
||||
return false;
|
||||
@ -1067,8 +1067,8 @@ bool WiFiClientSecure::_connectSSL(const char* hostName) {
|
||||
|
||||
_sc = std::make_shared<br_ssl_client_context>();
|
||||
_eng = &_sc->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
|
||||
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
|
||||
|
||||
if (!_sc || !_iobuf_in || !_iobuf_out) {
|
||||
_freeSSL(); // Frees _sc, _iobuf*
|
||||
@ -1183,8 +1183,8 @@ bool WiFiClientSecure::_connectSSLServerRSA(const X509List *chain,
|
||||
_oom_err = false;
|
||||
_sc_svr = std::make_shared<br_ssl_server_context>();
|
||||
_eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
|
||||
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
|
||||
|
||||
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
|
||||
_freeSSL();
|
||||
@ -1220,8 +1220,8 @@ bool WiFiClientSecure::_connectSSLServerEC(const X509List *chain,
|
||||
_oom_err = false;
|
||||
_sc_svr = std::make_shared<br_ssl_server_context>();
|
||||
_eng = &_sc_svr->eng; // Allocation/deallocation taken care of by the _sc shared_ptr
|
||||
_iobuf_in = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_out = std::shared_ptr<unsigned char>(new unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_in = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_in_size], std::default_delete<unsigned char[]>());
|
||||
_iobuf_out = std::shared_ptr<unsigned char>(new (std::nothrow) unsigned char[_iobuf_out_size], std::default_delete<unsigned char[]>());
|
||||
|
||||
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
|
||||
_freeSSL();
|
||||
@ -1421,7 +1421,7 @@ bool WiFiClientSecure::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint1
|
||||
default: return false; // Invalid size
|
||||
}
|
||||
int ttlLen = sizeof(clientHelloHead_P) + (2 + sizeof(suites_P)) + (sizeof(clientHelloTail_P) + 1);
|
||||
uint8_t *clientHello = new uint8_t[ttlLen];
|
||||
uint8_t *clientHello = new (std::nothrow) uint8_t[ttlLen];
|
||||
if (!clientHello) {
|
||||
DEBUG_BSSL("probeMaxFragmentLength: OOM\n");
|
||||
return false;
|
||||
@ -1580,21 +1580,21 @@ bool WiFiClientSecure::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint1
|
||||
// AXTLS compatibility interfaces
|
||||
bool WiFiClientSecure::setCACert(const uint8_t* pk, size_t size) {
|
||||
_axtls_ta = nullptr;
|
||||
_axtls_ta = std::shared_ptr<X509List>(new X509List(pk, size));
|
||||
_axtls_ta = std::shared_ptr<X509List>(new (std::nothrow) X509List(pk, size));
|
||||
_ta = _axtls_ta.get();
|
||||
return _ta ? true : false;
|
||||
}
|
||||
|
||||
bool WiFiClientSecure::setCertificate(const uint8_t* pk, size_t size) {
|
||||
_axtls_chain = nullptr;
|
||||
_axtls_chain = std::shared_ptr<X509List>(new X509List(pk, size));
|
||||
_axtls_chain = std::shared_ptr<X509List>(new (std::nothrow) X509List(pk, size));
|
||||
_chain = _axtls_chain.get();
|
||||
return _chain ? true : false;
|
||||
}
|
||||
|
||||
bool WiFiClientSecure::setPrivateKey(const uint8_t* pk, size_t size) {
|
||||
_axtls_sk = nullptr;
|
||||
_axtls_sk = std::shared_ptr<PrivateKey>(new PrivateKey(pk, size));
|
||||
_axtls_sk = std::shared_ptr<PrivateKey>(new (std::nothrow) PrivateKey(pk, size));
|
||||
_sk = _axtls_sk.get();
|
||||
return _sk ? true : false;
|
||||
|
||||
|
@ -186,7 +186,10 @@ long WiFiServer::_accept(tcp_pcb* apcb, long err) {
|
||||
|
||||
// always accept new PCB so incoming data can be stored in our buffers even before
|
||||
// user calls ::available()
|
||||
ClientContext* client = new ClientContext(apcb, &WiFiServer::_s_discard, this);
|
||||
ClientContext* client = new (std::nothrow) ClientContext(apcb, &WiFiServer::_s_discard, this);
|
||||
if (client == nullptr) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
// backlog doc:
|
||||
// http://lwip.100.n7.nabble.com/Problem-re-opening-listening-pbc-tt32484.html#a32494
|
||||
|
@ -107,8 +107,8 @@ WiFiClientSecure WiFiServerSecure::available(uint8_t* status) {
|
||||
void WiFiServerSecure::setServerKeyAndCert(const uint8_t *key, int keyLen, const uint8_t *cert, int certLen) {
|
||||
_axtls_chain = nullptr;
|
||||
_axtls_sk = nullptr;
|
||||
_axtls_chain = std::shared_ptr<X509List>(new X509List(cert, certLen));
|
||||
_axtls_sk = std::shared_ptr<PrivateKey>(new PrivateKey(key, keyLen));
|
||||
_axtls_chain = std::shared_ptr<X509List>(new (std::nothrow) X509List(cert, certLen));
|
||||
_axtls_sk = std::shared_ptr<PrivateKey>(new (std::nothrow) PrivateKey(key, keyLen));
|
||||
setRSACert(_axtls_chain.get(), _axtls_sk.get());
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,10 @@ uint8_t WiFiUDP::begin(uint16_t port)
|
||||
_ctx = 0;
|
||||
}
|
||||
|
||||
_ctx = new UdpContext;
|
||||
_ctx = new (std::nothrow) UdpContext;
|
||||
if (_ctx == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
_ctx->ref();
|
||||
return (_ctx->listen(IPAddress(), port)) ? 1 : 0;
|
||||
}
|
||||
@ -96,7 +99,10 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
|
||||
return 0;
|
||||
}
|
||||
|
||||
_ctx = new UdpContext;
|
||||
_ctx = new (std::nothrow) UdpContext;
|
||||
if (_ctx == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
_ctx->ref();
|
||||
ip_addr_t addr = IPADDR4_INIT(INADDR_ANY);
|
||||
if (!_ctx->listen(&addr, port)) {
|
||||
@ -147,7 +153,10 @@ int WiFiUDP::beginPacket(const char *host, uint16_t port)
|
||||
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
{
|
||||
if (!_ctx) {
|
||||
_ctx = new UdpContext;
|
||||
_ctx = new (std::nothrow) UdpContext;
|
||||
if (_ctx == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
_ctx->ref();
|
||||
}
|
||||
return (_ctx->connect(ip, port)) ? 1 : 0;
|
||||
@ -157,7 +166,10 @@ int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
|
||||
IPAddress interfaceAddress, int ttl)
|
||||
{
|
||||
if (!_ctx) {
|
||||
_ctx = new UdpContext;
|
||||
_ctx = new (std::nothrow) UdpContext;
|
||||
if (_ctx == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
_ctx->ref();
|
||||
}
|
||||
if (!_ctx->connect(multicastAddress, port)) {
|
||||
|
@ -374,7 +374,7 @@ public:
|
||||
if (!_pcb) {
|
||||
return 0;
|
||||
}
|
||||
return _write_from_source(new BufferDataSource(data, size));
|
||||
return _write_from_source(new (std::nothrow) BufferDataSource(data, size));
|
||||
}
|
||||
|
||||
size_t write(Stream& stream)
|
||||
@ -382,7 +382,7 @@ public:
|
||||
if (!_pcb) {
|
||||
return 0;
|
||||
}
|
||||
return _write_from_source(new BufferedStreamDataSource<Stream>(stream, stream.available()));
|
||||
return _write_from_source(new (std::nothrow) BufferedStreamDataSource<Stream>(stream, stream.available()));
|
||||
}
|
||||
|
||||
size_t write_P(PGM_P buf, size_t size)
|
||||
@ -391,7 +391,7 @@ public:
|
||||
return 0;
|
||||
}
|
||||
ProgmemStream stream(buf, size);
|
||||
return _write_from_source(new BufferedStreamDataSource<ProgmemStream>(stream, size));
|
||||
return _write_from_source(new (std::nothrow) BufferedStreamDataSource<ProgmemStream>(stream, size));
|
||||
}
|
||||
|
||||
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
|
||||
//Buffer too small?
|
||||
if (_bufferSize < min_buffer_size) {
|
||||
uint8_t *new_buffer = new uint8_t[min_buffer_size];
|
||||
uint8_t *new_buffer = new (std::nothrow) uint8_t[min_buffer_size];
|
||||
//If stream reading is ahead, than some data is already in the old buffer and needs to be copied to new resized buffer
|
||||
if (_buffer && stream_read > 0) {
|
||||
memcpy(new_buffer, _buffer.get(), stream_read);
|
||||
|
Reference in New Issue
Block a user