File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -84,9 +84,17 @@ namespace pcpp
84
84
85
85
if (curLayer != nullptr && curLayer->getOsiModelLayer () > parseUntilLayer)
86
86
{
87
- m_LastLayer = curLayer->getPrevLayer ();
88
- delete curLayer;
89
- m_LastLayer->m_NextLayer = nullptr ;
87
+ // don't delete the first layer. If already past the target layer, treat the same as if the layer was found.
88
+ if (curLayer == m_FirstLayer)
89
+ {
90
+ curLayer->m_IsAllocatedInPacket = true ;
91
+ }
92
+ else
93
+ {
94
+ m_LastLayer = curLayer->getPrevLayer ();
95
+ delete curLayer;
96
+ m_LastLayer->m_NextLayer = nullptr ;
97
+ }
90
98
}
91
99
92
100
if (m_LastLayer != nullptr && parseUntil == UnknownProtocol && parseUntilLayer == OsiModelLayerUnknown)
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ PTF_TEST_CASE(PacketTrailerTest);
58
58
PTF_TEST_CASE (ResizeLayerTest );
59
59
PTF_TEST_CASE (PrintPacketAndLayersTest );
60
60
PTF_TEST_CASE (ProtocolFamilyMembershipTest );
61
+ PTF_TEST_CASE (PacketParseLayerLimitTest );
61
62
62
63
// Implemented in HttpTests.cpp
63
64
PTF_TEST_CASE (HttpRequestParseMethodTest );
Original file line number Diff line number Diff line change @@ -1068,3 +1068,17 @@ PTF_TEST_CASE(ProtocolFamilyMembershipTest)
1068
1068
PTF_ASSERT_FALSE (httpLayer->isMemberOfProtocolFamily (pcpp::HTTPResponse));
1069
1069
PTF_ASSERT_FALSE (httpLayer->isMemberOfProtocolFamily (pcpp::IP));
1070
1070
}
1071
+
1072
+ PTF_TEST_CASE (PacketParseLayerLimitTest)
1073
+ {
1074
+ timeval time;
1075
+ gettimeofday (&time, nullptr );
1076
+
1077
+ READ_FILE_AND_CREATE_PACKET (0 , " PacketExamples/TcpPacketWithOptions3.dat" );
1078
+ pcpp::Packet packet0 (&rawPacket0, pcpp::OsiModelPhysicalLayer);
1079
+ PTF_ASSERT_EQUAL (packet0.getLastLayer (), packet0.getFirstLayer ());
1080
+
1081
+ READ_FILE_AND_CREATE_PACKET (1 , " PacketExamples/TcpPacketWithOptions3.dat" );
1082
+ pcpp::Packet packet1 (&rawPacket1, pcpp::OsiModelTransportLayer);
1083
+ PTF_ASSERT_EQUAL (packet1.getLastLayer ()->getOsiModelLayer (), pcpp::OsiModelTransportLayer);
1084
+ }
Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ int main(int argc, char* argv[])
161
161
PTF_RUN_TEST (ResizeLayerTest, " packet;resize" );
162
162
PTF_RUN_TEST (PrintPacketAndLayersTest, " packet;print" );
163
163
PTF_RUN_TEST (ProtocolFamilyMembershipTest, " packet" );
164
+ PTF_RUN_TEST (PacketParseLayerLimitTest, " packet" );
164
165
165
166
PTF_RUN_TEST (HttpRequestParseMethodTest, " http" );
166
167
PTF_RUN_TEST (HttpRequestLayerParsingTest, " http" );
You can’t perform that action at this time.
0 commit comments