Skip to content

Commit

Permalink
Merge pull request #125 from AndreyBronin/getPcapLiveDeviceByIp_bugfix
Browse files Browse the repository at this point in the history
getPcapLiveDeviceByIp null pointer dereference bugfix
  • Loading branch information
seladb authored Jul 31, 2018
2 parents c0bc3d0 + a2dcdbd commit 22a9198
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Pcap++/src/PcapLiveDeviceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ std::vector<IPv4Address>& PcapLiveDeviceList::getDnsServers()
PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const char* ipAddrAsString)
{
IPAddress::Ptr_t apAddr = IPAddress::fromString(ipAddrAsString);
if (!apAddr->isValid())
if (apAddr.get() == NULL || !apAddr->isValid())
{
LOG_ERROR("IP address illegal");
return NULL;
Expand Down
10 changes: 10 additions & 0 deletions Tests/Pcap++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,15 @@ PCAPP_TEST(TestPcapLiveDevice)
PCAPP_TEST_PASSED;
}

PCAPP_TEST(TestPcapLiveDeviceByInvalidIp)
{
PcapLiveDevice* liveDev = NULL;
liveDev = PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIp("eth0");
PCAPP_ASSERT(liveDev == NULL, "Cannot get live device by invalid Ip");

PCAPP_TEST_PASSED;
}

PCAPP_TEST(TestPcapLiveDeviceNoNetworking)
{
PcapLiveDevice* liveDev = NULL;
Expand Down Expand Up @@ -5593,6 +5602,7 @@ int main(int argc, char* argv[])
PCAPP_RUN_TEST(TestPcapLiveDeviceStatsMode, args, true);
PCAPP_RUN_TEST(TestPcapLiveDeviceBlockingMode, args, true);
PCAPP_RUN_TEST(TestWinPcapLiveDevice, args, true);
PCAPP_RUN_TEST(TestPcapLiveDeviceByInvalidIp, args, false);
PCAPP_RUN_TEST(TestPcapFilters, args, true);
PCAPP_RUN_TEST(TestSendPacket, args, true);
PCAPP_RUN_TEST(TestSendPackets, args, true);
Expand Down

0 comments on commit 22a9198

Please sign in to comment.