Skip to content

Commit 22a9198

Browse files
authored
Merge pull request seladb#125 from AndreyBronin/getPcapLiveDeviceByIp_bugfix
getPcapLiveDeviceByIp null pointer dereference bugfix
2 parents c0bc3d0 + a2dcdbd commit 22a9198

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Pcap++/src/PcapLiveDeviceList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ std::vector<IPv4Address>& PcapLiveDeviceList::getDnsServers()
281281
PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const char* ipAddrAsString)
282282
{
283283
IPAddress::Ptr_t apAddr = IPAddress::fromString(ipAddrAsString);
284-
if (!apAddr->isValid())
284+
if (apAddr.get() == NULL || !apAddr->isValid())
285285
{
286286
LOG_ERROR("IP address illegal");
287287
return NULL;

Tests/Pcap++Test/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,15 @@ PCAPP_TEST(TestPcapLiveDevice)
12681268
PCAPP_TEST_PASSED;
12691269
}
12701270

1271+
PCAPP_TEST(TestPcapLiveDeviceByInvalidIp)
1272+
{
1273+
PcapLiveDevice* liveDev = NULL;
1274+
liveDev = PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIp("eth0");
1275+
PCAPP_ASSERT(liveDev == NULL, "Cannot get live device by invalid Ip");
1276+
1277+
PCAPP_TEST_PASSED;
1278+
}
1279+
12711280
PCAPP_TEST(TestPcapLiveDeviceNoNetworking)
12721281
{
12731282
PcapLiveDevice* liveDev = NULL;
@@ -5593,6 +5602,7 @@ int main(int argc, char* argv[])
55935602
PCAPP_RUN_TEST(TestPcapLiveDeviceStatsMode, args, true);
55945603
PCAPP_RUN_TEST(TestPcapLiveDeviceBlockingMode, args, true);
55955604
PCAPP_RUN_TEST(TestWinPcapLiveDevice, args, true);
5605+
PCAPP_RUN_TEST(TestPcapLiveDeviceByInvalidIp, args, false);
55965606
PCAPP_RUN_TEST(TestPcapFilters, args, true);
55975607
PCAPP_RUN_TEST(TestSendPacket, args, true);
55985608
PCAPP_RUN_TEST(TestSendPackets, args, true);

0 commit comments

Comments
 (0)