Skip to content

Commit 07241dd

Browse files
authored
Avoid UB and abort on nullptr buffer (#7822)
* Avoid UB and abort on nullptr buffer * Report OOM on return value
1 parent 34545a1 commit 07241dd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

libraries/Netdump/src/Netdump.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,25 @@ void Netdump::fileDump(File& outfile, const Filter nf)
8484
fileDumpProcess(outfile, ndp);
8585
}, nf);
8686
}
87-
void Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
87+
bool Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
8888
{
8989

9090
if (!packetBuffer)
9191
{
9292
packetBuffer = new (std::nothrow) char[tcpBufferSize];
93+
94+
if (!packetBuffer)
95+
{
96+
return false;
97+
}
9398
}
9499
bufferIndex = 0;
95100

96101
schedule_function([&tcpDumpServer, this, nf]()
97102
{
98103
tcpDumpLoop(tcpDumpServer, nf);
99104
});
105+
return true;
100106
}
101107

102108
void Netdump::capture(int netif_idx, const char* data, size_t len, int out, int success)

libraries/Netdump/src/Netdump.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Netdump
5353

5454
void printDump(Print& out, Packet::PacketDetail ndd, const Filter nf = nullptr);
5555
void fileDump(File& outfile, const Filter nf = nullptr);
56-
void tcpDump(WiFiServer &tcpDumpServer, const Filter nf = nullptr);
56+
bool tcpDump(WiFiServer &tcpDumpServer, const Filter nf = nullptr);
5757

5858

5959
private:

0 commit comments

Comments
 (0)