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/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 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 = {