Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
egecetin committed Aug 25, 2024
2 parents 6f56f63 + fa22ff2 commit d0109c3
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 30 deletions.
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-symlinks
- id: end-of-file-fixer
- id: forbid-submodules
- id: mixed-line-ending
args: ['--fix=lf']
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
Expand All @@ -23,7 +29,7 @@ repos:
rev: v1.3.5
hooks:
- id: clang-format
args: ["--style=file"] # Use the .clang-format file for configuration
args: ["--style=file", "-i"] # Use the .clang-format file for configuration and apply all fixes
files: ^(Common\+\+|Packet\+\+|Pcap\+\+|Tests|Examples)/.*\.(cpp|h)$
- id: cppcheck
args: ["--std=c++11", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr", "--force"]
Expand All @@ -38,3 +44,7 @@ repos:
- id: typos
args: ['--config=typos-config.toml']
pass_filenames: false
- repo: https://github.com/lovesegfault/beautysh
rev: v6.2.1
hooks:
- id: beautysh
7 changes: 6 additions & 1 deletion Examples/DnsSpoofing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* address as the resolved IP. Then it's sent back on the network on the same interface
*/

#include <stdexcept>
#include <vector>
#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -205,11 +206,15 @@ void handleDnsRequest(pcpp::RawPacket* packet, pcpp::PcapLiveDevice* dev, void*
ip4Layer->setDstIPv4Address(srcIP.getIPv4());
ip4Layer->getIPv4Header()->ipId = 0;
}
else
else if (ip6Layer != nullptr)
{
ip6Layer->setSrcIPv6Address(ip6Layer->getDstIPv6Address());
ip6Layer->setDstIPv6Address(srcIP.getIPv6());
}
else
{
throw std::logic_error("IPLayer should be either IPv4Layer or IPv6Layer");
}

// reverse src and dst UDP ports
uint16_t srcPort = udpLayer->getUdpHeader()->portSrc;
Expand Down
5 changes: 5 additions & 0 deletions Examples/IcmpFileTransfer/IcmpFileTransfer-pitcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <stdlib.h>
#include <stdexcept>
#include <iostream>
#include <fstream>
#ifndef _MSC_VER
Expand Down Expand Up @@ -37,6 +38,10 @@ void usleep(__int64 usec)
ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time

timer = CreateWaitableTimer(NULL, TRUE, NULL);
if (timer == nullptr)
{
throw std::runtime_error("Could not create waitable timer with error: " + std::to_string(GetLastError()));
}
SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
Expand Down
8 changes: 4 additions & 4 deletions Packet++/header/HttpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,13 @@ namespace pcpp
class HttpRequestFirstLineException : public std::exception
{
public:
~HttpRequestFirstLineException() throw()
~HttpRequestFirstLineException() noexcept
{}
void setMessage(const std::string& message)
{
m_Message = message;
}
virtual const char* what() const throw()
virtual const char* what() const noexcept
{
return m_Message.c_str();
}
Expand Down Expand Up @@ -857,13 +857,13 @@ namespace pcpp
class HttpResponseFirstLineException : public std::exception
{
public:
~HttpResponseFirstLineException() throw()
~HttpResponseFirstLineException() noexcept
{}
void setMessage(const std::string& message)
{
m_Message = message;
}
virtual const char* what() const throw()
virtual const char* what() const noexcept
{
return m_Message.c_str();
}
Expand Down
8 changes: 4 additions & 4 deletions Packet++/header/SipLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,13 @@ namespace pcpp
class SipRequestFirstLineException : public std::exception
{
public:
~SipRequestFirstLineException() throw()
~SipRequestFirstLineException() noexcept
{}
void setMessage(const std::string& message)
{
m_Message = message;
}
virtual const char* what() const throw()
virtual const char* what() const noexcept
{
return m_Message.c_str();
}
Expand Down Expand Up @@ -748,13 +748,13 @@ namespace pcpp
class SipResponseFirstLineException : public std::exception
{
public:
~SipResponseFirstLineException() throw()
~SipResponseFirstLineException() noexcept
{}
void setMessage(const std::string& message)
{
m_Message = message;
}
virtual const char* what() const throw()
virtual const char* what() const noexcept
{
return m_Message.c_str();
}
Expand Down
4 changes: 3 additions & 1 deletion Packet++/src/FtpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace pcpp
std::string field = getCommandString();

for (size_t idx = 0; idx < field.size(); ++idx)
val |= (field.c_str()[idx] << (idx * 8));
{
val |= static_cast<size_t>(field.c_str()[idx]) << (idx * 8);
}

return static_cast<FtpCommand>(val);
}
Expand Down
5 changes: 5 additions & 0 deletions Packet++/src/IPv6Layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define LOG_MODULE PacketLogModuleIPv6Layer

#include <stdexcept>
#include "IPv6Layer.h"
#include "IPv4Layer.h"
#include "PayloadLayer.h"
Expand Down Expand Up @@ -133,6 +134,10 @@ namespace pcpp
}
else
{
if (curExt == nullptr)
{
throw std::logic_error("curExt is nullptr");
}
curExt->setNextHeader(newExt);
curExt = curExt->getNextHeader();
}
Expand Down
4 changes: 2 additions & 2 deletions Packet++/src/SipLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ namespace pcpp
SipRequestLayer::SipRequestLayer(SipMethod method, const std::string& requestUri, const std::string& version)
{
m_Protocol = SIPRequest;
m_FirstLine = new SipRequestFirstLine(this, method, std::move(version), std::move(requestUri));
m_FirstLine = new SipRequestFirstLine(this, method, version, requestUri);
m_FieldsOffset = m_FirstLine->getSize();
}

Expand Down Expand Up @@ -598,7 +598,7 @@ namespace pcpp
const std::string& sipVersion)
{
m_Protocol = SIPResponse;
m_FirstLine = new SipResponseFirstLine(this, std::move(sipVersion), statusCode, std::move(statusCodeString));
m_FirstLine = new SipResponseFirstLine(this, sipVersion, statusCode, std::move(statusCodeString));
m_FieldsOffset = m_FirstLine->getSize();
}

Expand Down
4 changes: 3 additions & 1 deletion Packet++/src/SmtpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ namespace pcpp
std::string field = getCommandString();

for (size_t idx = 0; idx < field.size(); ++idx)
val |= (field.c_str()[idx] << (idx * 8));
{
val |= static_cast<size_t>(field.c_str()[idx]) << (idx * 8);
}

return static_cast<SmtpCommand>(val);
}
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/TextBasedProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ namespace pcpp
{
m_NameValueSeparator = nameValueSeparator;
m_SpacesAllowedBetweenNameAndValue = spacesAllowedBetweenNameAndValue;
initNewField(std::move(name), std::move(value));
initNewField(name, value);
}

void HeaderField::initNewField(const std::string& name, const std::string& value)
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/VrrpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ namespace pcpp

size_t ipAddrOffset = 0;
uint8_t* newIpAddresses = getData() + offset;
for (auto ipAddress : ipAddresses)
for (auto const& ipAddress : ipAddresses)
{
copyIPAddressToData(newIpAddresses + ipAddrOffset, ipAddress);
ipAddrOffset += ipAddrLen;
Expand Down
10 changes: 5 additions & 5 deletions Tests/Fuzzers/RegressionTests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

if [ -z "${SAMPLES}" ]; then
SAMPLES=regression_samples
SAMPLES=regression_samples
fi
if [ -z "${BINARY}" ]; then
BINARY=../Bin/FuzzTarget
BINARY=../Bin/FuzzTarget
fi

ERR_CODE=0
Expand All @@ -14,12 +14,12 @@ GREEN='\033[0;32m'
NC='\033[0m'

for sample in $(ls ${SAMPLES}); do
echo -n "Running sample $sample..."
"${BINARY}" "$SAMPLES/$sample" &> /dev/null && echo -e "${GREEN}[OK]${NC}" || { FAILED=True && echo -e "${RED}[FAIL]${NC}"; }
echo -n "Running sample $sample..."
"${BINARY}" "$SAMPLES/$sample" &> /dev/null && echo -e "${GREEN}[OK]${NC}" || { FAILED=True && echo -e "${RED}[FAIL]${NC}"; }
done

if [[ ! -z $FAILED ]]; then
ERR_CODE=1
ERR_CODE=1
fi

exit $ERR_CODE
3 changes: 1 addition & 2 deletions Tests/Fuzzers/ossfuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ cmake -DPCAPPP_BUILD_FUZZERS=ON -DPCAPPP_BUILD_TESTS=OFF -DPCAPPP_BUILD_EXAMPLES
cmake --build $TARGETS_DIR -j

# Copy target and options
FUZZERS="
FuzzTarget \
FUZZERS="FuzzTarget \
FuzzTargetNg \
FuzzTargetSnoop \
FuzzWriter \
Expand Down
2 changes: 1 addition & 1 deletion Tests/Pcap++Test/Tests/IpMacTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ PTF_TEST_CASE(TestGetMacAddress)
std::string ipsInArpTableAsString;
#ifdef _WIN32
ipsInArpTableAsString =
pcpp::executeShellCommand("arp -a | for /f \"tokens=1\" \%i in ('findstr dynamic') do @echo \%i");
pcpp::executeShellCommand(R"(arp -a | for /f "tokens=1" %i in ('findstr dynamic') do @echo %i)");
ipsInArpTableAsString.erase(std::remove(ipsInArpTableAsString.begin(), ipsInArpTableAsString.end(), ' '),
ipsInArpTableAsString.end());
#else
Expand Down
13 changes: 8 additions & 5 deletions Tests/Pcap++Test/Tests/LiveDeviceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "../Common/TestUtils.h"
#include "../Common/PcapFileNamesDef.h"
#include <array>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cstdio>
#if defined(_WIN32)
Expand Down Expand Up @@ -821,9 +823,8 @@ PTF_TEST_CASE(TestSendPackets)
pcpp::PcapFileReaderDevice fileReaderDev(EXAMPLE_PCAP_PATH);
PTF_ASSERT_TRUE(fileReaderDev.open());

pcpp::RawPacket rawPacketArr[10000];
std::vector<pcpp::RawPacket> rawPacketArr(10000);
pcpp::PointerVector<pcpp::Packet> packetVec;
pcpp::Packet* packetArr[10000];
int packetsRead = 0;
while (fileReaderDev.getNextPacket(rawPacketArr[packetsRead]))
{
Expand All @@ -832,11 +833,13 @@ PTF_TEST_CASE(TestSendPackets)
}

// send packets as RawPacket array
int packetsSentAsRaw = liveDev->sendPackets(rawPacketArr, packetsRead);
int packetsSentAsRaw = liveDev->sendPackets(rawPacketArr.data(), packetsRead);

// send packets as parsed EthPacekt array
std::copy(packetVec.begin(), packetVec.end(), packetArr);
int packetsSentAsParsed = liveDev->sendPackets(packetArr, packetsRead);
std::vector<pcpp::Packet*> packetArr;
packetArr.reserve(10000);
std::copy(packetVec.begin(), packetVec.end(), std::back_inserter(packetArr));
int packetsSentAsParsed = liveDev->sendPackets(packetArr.data(), packetsRead);

PTF_ASSERT_EQUAL(packetsSentAsRaw, packetsRead);
PTF_ASSERT_EQUAL(packetsSentAsParsed, packetsRead);
Expand Down
7 changes: 7 additions & 0 deletions Tests/PcppTestFramework/PcppTestFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "memplumber.h"
#include "PcppTestFrameworkCommon.h"

#ifdef _MSC_VER
# define _PTF_MSVC_SUPPRESS_C26444 _Pragma("warning(suppress: 26444)");
#else
# define _PTF_MSVC_SUPPRESS_C26444
#endif // _MSC_VER

#define _PTF_PRINT_TYPE_ACTUAL(exp, val) val
#define _PTF_PRINT_TYPE_EXPECTED(exp, val) val
#define hex_PTF_PRINT_TYPE_ACTUAL(exp, val) "0x" << std::hex << +val << std::dec
Expand Down Expand Up @@ -217,6 +223,7 @@
std::string messageCaught = ""; \
try \
{ \
_PTF_MSVC_SUPPRESS_C26444 \
expression; \
} \
catch (const exception_type& e) \
Expand Down
Empty file modified cmake/setup_dpdk.py
100644 → 100755
Empty file.

0 comments on commit d0109c3

Please sign in to comment.