mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.91k stars 375 forks source link

OfflinePacketFilter gets exception from free() when pcap filter is invalid #359

Open srkolb opened 5 years ago

srkolb commented 5 years ago

Creating an OfflinePacketFilter instance with an invalid filter should throw an invalid_pcap_filter exception but it appears it cleans up the pcap handle before throwing the exception and then again in the destructor which results in a invalid pointer for free().

Add this test case to offline_packet_filter_test.cpp:

TEST_F(OfflinePacketFilterTest, InvalidPcapFilterThrowsException) { EXPECT_THROW(OfflinePacketFilter filter("this is not a valid filter", DataLinkType()), invalid_pcap_filter); }

Running main() from gtest_main.cc [==========] Running 5 tests from 1 test case. [----------] Global test environment set-up. [----------] 5 tests from OfflinePacketFilterTest [ RUN ] OfflinePacketFilterTest.CopyConstructor [ OK ] OfflinePacketFilterTest.CopyConstructor (0 ms) [ RUN ] OfflinePacketFilterTest.MatchesFilterEthTcp [ OK ] OfflinePacketFilterTest.MatchesFilterEthTcp (1 ms) [ RUN ] OfflinePacketFilterTest.MatchesFilterEth [ OK ] OfflinePacketFilterTest.MatchesFilterEth (0 ms) [ RUN ] OfflinePacketFilterTest.MatchesFilterSLLTcp [ OK ] OfflinePacketFilterTest.MatchesFilterSLLTcp (0 ms) [ RUN ] OfflinePacketFilterTest.InvalidPcapFilterThrowsException Error in `tests/offline_packet_filter_test': free(): invalid pointer: 0x00007ffefb5113d0 Off