From ed6fdd055c9c9da8028a4f67f31441613ef65c39 Mon Sep 17 00:00:00 2001 From: s-genereux Date: Tue, 18 Feb 2025 11:48:19 -0500 Subject: [PATCH 1/2] command only ftp packet fix and test --- Packet++/src/SingleCommandTextProtocol.cpp | 6 ++++-- Tests/Packet++Test/Tests/FtpTests.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Packet++/src/SingleCommandTextProtocol.cpp b/Packet++/src/SingleCommandTextProtocol.cpp index 04b0841b7b..ebb3b3cd81 100644 --- a/Packet++/src/SingleCommandTextProtocol.cpp +++ b/Packet++/src/SingleCommandTextProtocol.cpp @@ -135,10 +135,12 @@ namespace pcpp size_t offset = getArgumentFieldOffset(); // We don't want to get delimiter so add 1 for start unless there is no command, - // and we don't want to trailing newline characters so remove 2 and remove addition from start point int addition = offset ? 1 : 0; - if (offset != (m_DataLen - 1)) + + // Check if command-only packet (-2 to account for len/position comparison and size of CRLF) + if (offset != (m_DataLen - 2)) { + // We don't want to trailing newline characters so remove 2 and remove addition from start point auto option = std::string((char*)&m_Data[offset + addition], m_DataLen - (offset + 2 + addition)); // Remove XXX- and XXX since they are delimiters of the protocol where XXX is the usually status code diff --git a/Tests/Packet++Test/Tests/FtpTests.cpp b/Tests/Packet++Test/Tests/FtpTests.cpp index 9f243ae836..d9047dce24 100644 --- a/Tests/Packet++Test/Tests/FtpTests.cpp +++ b/Tests/Packet++Test/Tests/FtpTests.cpp @@ -88,6 +88,19 @@ PTF_TEST_CASE(FtpParsingTests) PTF_ASSERT_EQUAL(ftpDataLayer->getDataLen(), 1452); PTF_ASSERT_EQUAL(ftpDataLayer->toString(), "FTP Data"); + // Test IPv4 Command Only Request Packet + READ_FILE_AND_CREATE_PACKET(7, "PacketExamples/ftpIpv4CmdOnlyReq.dat"); + + pcpp::Packet ftpPacket7(&rawPacket7); + pcpp::FtpRequestLayer* ftpLayer7 = ftpPacket7.getLayerOfType(); + + PTF_ASSERT_NOT_NULL(ftpLayer7); + PTF_ASSERT_EQUAL(int(ftpLayer7->getCommand()), int(pcpp::FtpRequestLayer::FtpCommand::SYST)); + PTF_ASSERT_EQUAL(ftpLayer7->getCommandString(), "SYST"); + PTF_ASSERT_EQUAL(ftpLayer7->getCommandOption(), ""); + PTF_ASSERT_EQUAL(ftpLayer7->toString(), "FTP Request: SYST"); + PTF_ASSERT_FALSE(ftpLayer7->isMultiLine()); + // Command codes // clang-format off std::vector> possibleCommandCodes = { From b88e9647cf6c90b77e2e570a84ae3fb782f3a65b Mon Sep 17 00:00:00 2001 From: s-genereux Date: Tue, 18 Feb 2025 12:10:05 -0500 Subject: [PATCH 2/2] added testcase file --- Tests/Packet++Test/PacketExamples/ftpIpv4CmdOnlyReq.dat | 1 + 1 file changed, 1 insertion(+) create mode 100644 Tests/Packet++Test/PacketExamples/ftpIpv4CmdOnlyReq.dat diff --git a/Tests/Packet++Test/PacketExamples/ftpIpv4CmdOnlyReq.dat b/Tests/Packet++Test/PacketExamples/ftpIpv4CmdOnlyReq.dat new file mode 100644 index 0000000000..c3b7fd274e --- /dev/null +++ b/Tests/Packet++Test/PacketExamples/ftpIpv4CmdOnlyReq.dat @@ -0,0 +1 @@ +00000000000000000000000008004510003a7efb40004006bdb07f0000017f000001991a0015a11240363cc091be80187fe6fe2e00000101080aaefa0886aef8fc96535953540d0a