Skip to content

Commit

Permalink
Merge branch 'dev' into 20230812HttpStatusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos authored Aug 16, 2023
2 parents 3eb74d8 + aa4e62d commit 8002ca2
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: codespell
pass_filenames: false
- repo: https://github.com/crate-ci/typos
rev: v1.16.1
rev: v1.16.5
hooks:
- id: typos
args: ['--config=typos-config.toml']
Expand Down
1 change: 0 additions & 1 deletion Common++/header/SystemUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ namespace pcpp
* Static init method which should be called once at the beginning of the main method.
* @param[in] argc The argc param from main()
* @param[in] argv The argv param from main()
* @return No return value
*/
// cppcheck-suppress constParameter
static void init(int argc, char* argv[])
Expand Down
2 changes: 0 additions & 2 deletions Packet++/header/DhcpV6Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ namespace pcpp
/**
* Set the message type for this layer
* @param[in] messageType The message type to set
* @return No return value
*/
void setMessageType(DhcpV6MessageType messageType);

Expand All @@ -321,7 +320,6 @@ namespace pcpp
/**
* Set the transaction ID for this DHCPv6 message
* @param[in] transactionId The transaction ID value to set
* @return No return value
*/
void setTransactionID(uint32_t transactionId) const;

Expand Down
1 change: 0 additions & 1 deletion Packet++/header/DnsLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ namespace pcpp

/**
* Does nothing for this layer
* @return No return value
*/
virtual void computeCalculateFields() {}

Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/DnsResourceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ namespace pcpp
* copied from this byte array to the object
* @param[in] dataLen The byte array size
*/
GenericDnsResourceData(uint8_t* dataPtr, size_t dataLen);
GenericDnsResourceData(const uint8_t* dataPtr, size_t dataLen);

/**
* A c'tor for this class
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/DnsLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ DnsResource* DnsLayer::addResource(DnsResourceType resType, const std::string& n
uint32_t ttl, IDnsResourceData* data)
{
// create new query on temporary buffer
uint8_t newResourceRawData[256];
uint8_t newResourceRawData[4096];
memset(newResourceRawData, 0, sizeof(newResourceRawData));

DnsResource* newResource = new DnsResource(newResourceRawData, resType);
Expand Down
10 changes: 5 additions & 5 deletions Packet++/src/DnsResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace pcpp
IDnsResource::IDnsResource(DnsLayer* dnsLayer, size_t offsetInLayer)
: m_DnsLayer(dnsLayer), m_OffsetInLayer(offsetInLayer), m_NextResource(nullptr)
{
char decodedName[256];
char decodedName[4096];
m_NameLength = decodeName((const char*)getRawData(), decodedName);
if (m_NameLength > 0)
m_DecodedName = decodedName;
Expand Down Expand Up @@ -83,8 +83,8 @@ size_t IDnsResource::decodeName(const char* encodedName, char* result, int itera
return 0;
}

char tempResult[256];
memset(tempResult, 0, 256);
char tempResult[4096];
memset(tempResult, 0, sizeof(tempResult));
int i = 0;
decodeName((const char*)(m_DnsLayer->m_Data + offsetInLayer), tempResult, iteration+1);
while (tempResult[i] != 0 && decodedNameLength < 255)
Expand Down Expand Up @@ -224,7 +224,7 @@ void IDnsResource::setDnsClass(DnsClass newClass)

bool IDnsResource::setName(const std::string& newName)
{
char encodedName[256];
char encodedName[4096];
size_t encodedNameLen = 0;
encodeName(newName, encodedName, encodedNameLen);
if (m_DnsLayer != nullptr)
Expand Down Expand Up @@ -345,7 +345,7 @@ bool DnsResource::setData(IDnsResourceData* data)
{
// convert data to byte array according to the DNS type
size_t dataLength = 0;
uint8_t dataAsByteArr[256];
uint8_t dataAsByteArr[4096];

if (data == nullptr)
{
Expand Down
8 changes: 4 additions & 4 deletions Packet++/src/DnsResourceData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ StringDnsResourceData::StringDnsResourceData(const uint8_t* dataPtr, size_t data
{
if (dataPtr && dataLen > 0)
{
char tempResult[256];
char tempResult[4096];
decodeName((const char*)dataPtr, tempResult, dnsResource);
m_Data = tempResult;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ MxDnsResourceData::MxDnsResourceData(uint8_t* dataPtr, size_t dataLen, IDnsResou
if (dataPtr && dataLen > 0)
{
uint16_t preference = be16toh(*(uint16_t*)dataPtr);
char tempMX[256];
char tempMX[4096];
decodeName((const char*)(dataPtr + sizeof(preference)), tempMX, dnsResource);
m_Data.preference = preference;
m_Data.mailExchange = tempMX;
Expand Down Expand Up @@ -150,7 +150,7 @@ bool MxDnsResourceData::toByteArr(uint8_t* arr, size_t& arrLength, IDnsResource*
return true;
}

GenericDnsResourceData::GenericDnsResourceData(uint8_t* dataPtr, size_t dataLen)
GenericDnsResourceData::GenericDnsResourceData(const uint8_t* dataPtr, size_t dataLen)
{
m_Data = nullptr;
m_DataLen = 0;
Expand Down Expand Up @@ -218,7 +218,7 @@ bool GenericDnsResourceData::toByteArr(uint8_t* arr, size_t& arrLength, IDnsReso
{
if (m_DataLen == 0 || m_Data == nullptr)
{
PCPP_LOG_ERROR("Input data is null or illegal");
PCPP_LOG_ERROR("Input data is null or illegal" << "|m_DataLen:" << m_DataLen);
return false;
}

Expand Down
1 change: 0 additions & 1 deletion Pcap++/header/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace pcpp

/**
* Close the device
* @return No return value
*/
virtual void close() = 0;

Expand Down
1 change: 0 additions & 1 deletion Pcap++/header/DpdkDeviceList.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace pcpp
/**
* An abstract method that must be implemented by child class. It's the indication for the worker to stop running. After
* this method is called the caller expects the worker to stop running as fast as possible
* @return No return value
*/
virtual void stop() = 0;

Expand Down
1 change: 0 additions & 1 deletion Pcap++/header/PcapDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ namespace pcpp
/**
* Get statistics from the device
* @param[out] stats An object containing the stats
* @return No return value
*/
virtual void getStatistics(PcapStats& stats) const = 0;

Expand Down
1 change: 0 additions & 1 deletion Pcap++/header/PcapFileDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace pcpp

/**
* Close the file
* @return No return value
*/
virtual void close();
};
Expand Down
2 changes: 0 additions & 2 deletions Pcap++/header/PcapFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace pcpp
/**
* A method that parses the class instance into BPF string format
* @param[out] result An empty string that the parsing will be written into. If the string isn't empty, its content will be overridden
* @return No return value
*/
virtual void parseToString(std::string& result) = 0;

Expand Down Expand Up @@ -179,7 +178,6 @@ namespace pcpp
* A method that parses the class instance into BPF string format
* @param[out] result An empty string that the parsing will be written into. If the string isn't empty, its content will be overridden
* If the filter is not valid the result will be an empty string
* @return No return value
*/
virtual void parseToString(std::string& result);

Expand Down
2 changes: 1 addition & 1 deletion Pcap++/header/PcapLiveDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace pcpp
* @param[in] userCookie A pointer to the object put by the user when packet capturing stared
* @return True when main thread should stop blocking or false otherwise
*/
typedef bool (*OnPacketArrivesStopBlocking)(RawPacket* pPacket, PcapLiveDevice* pDevice, void* userData);
typedef bool (*OnPacketArrivesStopBlocking)(RawPacket* pPacket, PcapLiveDevice* pDevice, void* userCookie);


/**
Expand Down
1 change: 1 addition & 0 deletions Tests/Packet++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ PTF_TEST_CASE(DnsLayerEditTest);
PTF_TEST_CASE(DnsLayerRemoveResourceTest);
PTF_TEST_CASE(DnsOverTcpParsingTest);
PTF_TEST_CASE(DnsOverTcpCreationTest);
PTF_TEST_CASE(DnsLayerAddDnsKeyTest);

// Implemented in IcmpTests.cpp
PTF_TEST_CASE(IcmpParsingTest);
Expand Down
12 changes: 12 additions & 0 deletions Tests/Packet++Test/Tests/DnsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,19 @@ PTF_TEST_CASE(DnsLayerResourceCreationTest)
PTF_ASSERT_BUF_COMPARE(dnsEdit7Packet.getRawPacket()->getRawData(), buffer7, bufferLength7);
} // DnsLayerResourceCreationTest

PTF_TEST_CASE(DnsLayerAddDnsKeyTest)
{

// data length overflow 256
const std::string dnskey = "AwEAAaz/tAm8yTn4Mfeh5eyI96WSVexTBAvkMgJzkKTOiW1vkIbzxeF3+/4RgWOq7HrxRixHlFlExOLAJr5emLvN7SWXgnLh4+B5xQ \
lNVz8Og8kvArMtNROxVQuCaSnIDdD5LKyWbRd2n9WGe2R8PzgCmr3EgVLrjyBxWezF0jLHwVN8efS3rCj/EWgvIWgb9tarpVUDK/b58Da+sqqls3eNbuv7pr+eoZG+Sr \
DK6nWeL3c6H5Apxz7LjVc1uTIdsIXxuOLYA4/ilBmSVIzuDWfdRUfhHdY6+cn8HFRm+2hM8AnXGXws9555KrUB5qihylGa8subX2Nn6UwNR1AkUTV74bU=";

pcpp::DnsLayer dnsLayer;
pcpp::GenericDnsResourceData genericData(reinterpret_cast<const uint8_t*>(dnskey.c_str()), dnskey.size());
const auto* additional = dnsLayer.addAnswer("github.com", pcpp::DNS_TYPE_DNSKEY, pcpp::DNS_CLASS_IN, 32, &genericData);
PTF_ASSERT_NOT_NULL(additional);
}

PTF_TEST_CASE(DnsLayerEditTest)
{
Expand Down
1 change: 1 addition & 0 deletions Tests/Packet++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ int main(int argc, char* argv[])
PTF_RUN_TEST(DnsLayerRemoveResourceTest, "dns");
PTF_RUN_TEST(DnsOverTcpParsingTest, "dns");
PTF_RUN_TEST(DnsOverTcpCreationTest, "dns");
PTF_RUN_TEST(DnsLayerAddDnsKeyTest, "dns");

PTF_RUN_TEST(IcmpParsingTest, "icmp");
PTF_RUN_TEST(IcmpCreationTest, "icmp");
Expand Down

0 comments on commit 8002ca2

Please sign in to comment.