1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-07 16:23:38 +03:00

Avoid UB and abort on nullptr buffer (#7822)

* Avoid UB and abort on nullptr buffer
* Report OOM on return value
This commit is contained in:
Paulo Cabral Sanz 2021-01-12 18:39:55 -03:00 committed by GitHub
parent 34545a160d
commit 07241dd407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -84,12 +84,17 @@ void Netdump::fileDump(File& outfile, const Filter nf)
fileDumpProcess(outfile, ndp);
}, nf);
}
void Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
bool Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
{
if (!packetBuffer)
{
packetBuffer = new (std::nothrow) char[tcpBufferSize];
if (!packetBuffer)
{
return false;
}
}
bufferIndex = 0;
@ -97,6 +102,7 @@ void Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
{
tcpDumpLoop(tcpDumpServer, nf);
});
return true;
}
void Netdump::capture(int netif_idx, const char* data, size_t len, int out, int success)

View File

@ -53,7 +53,7 @@ public:
void printDump(Print& out, Packet::PacketDetail ndd, const Filter nf = nullptr);
void fileDump(File& outfile, const Filter nf = nullptr);
void tcpDump(WiFiServer &tcpDumpServer, const Filter nf = nullptr);
bool tcpDump(WiFiServer &tcpDumpServer, const Filter nf = nullptr);
private: