Merge branch 'develop' into wip-cppcheck271-part2

This commit is contained in:
g. economou
2024-05-17 11:08:09 +03:00
committed by GitHub
211 changed files with 3167 additions and 2125 deletions

View File

@@ -202,7 +202,7 @@ struct FiveTuple {
unsigned int dstPort;
// Construct a FiveTuple from a TCP or UDP packet.
FiveTuple(const struct ip *iphdr) {
explicit FiveTuple(const struct ip *iphdr) {
// IP fields
protocol = iphdr->ip_p;
srcAddr = iphdr->ip_src.s_addr;
@@ -391,7 +391,7 @@ public:
// Close all open Hyperscan streams (potentially generating any
// end-anchored matches)
void closeStreams() {
for (auto &stream : streams) {
for (const auto &stream : streams) {
hs_error_t err =
hs_close_stream(stream, scratch, onMatch, &matchCount);
if (err != HS_SUCCESS) {
@@ -444,7 +444,7 @@ class Sigdata {
public:
Sigdata() {}
Sigdata(const char *filename) {
explicit Sigdata(const char *filename) {
parseFile(filename, patterns, flags, ids, originals);
}
@@ -568,7 +568,7 @@ double measure_block_time(Benchmark &bench, unsigned int repeatCount) {
}
static
double eval_set(Benchmark &bench, Sigdata &sigs, unsigned int mode,
double eval_set(Benchmark &bench, const Sigdata &sigs, unsigned int mode,
unsigned repeatCount, Criterion criterion,
bool diagnose = true) {
double compileTime = 0;
@@ -608,8 +608,9 @@ double eval_set(Benchmark &bench, Sigdata &sigs, unsigned int mode,
scan_time = measure_stream_time(bench, repeatCount);
}
size_t bytes = bench.bytes();
size_t matches = bench.matches();
if (diagnose) {
size_t matches = bench.matches();
std::ios::fmtflags f(cout.flags());
cout << "Scan time " << std::fixed << std::setprecision(3) << scan_time
<< " sec, Scanned " << bytes * repeatCount << " bytes, Throughput "

View File

@@ -100,15 +100,14 @@ struct FiveTuple {
unsigned int dstPort;
// Construct a FiveTuple from a TCP or UDP packet.
FiveTuple(const struct ip *iphdr) {
explicit FiveTuple(const struct ip *iphdr) {
// IP fields
protocol = iphdr->ip_p;
srcAddr = iphdr->ip_src.s_addr;
dstAddr = iphdr->ip_dst.s_addr;
// UDP/TCP ports
const struct udphdr *uh =
(const struct udphdr *)(((const char *)iphdr) + (iphdr->ip_hl * 4));
const struct udphdr *uh = reinterpret_cast<const struct udphdr *>(iphdr) + (iphdr->ip_hl * 4);
srcPort = uh->uh_sport;
dstPort = uh->uh_dport;
}
@@ -137,7 +136,7 @@ static
int onMatch(unsigned int id, unsigned long long from, unsigned long long to,
unsigned int flags, void *ctx) {
// Our context points to a size_t storing the match count
size_t *matches = (size_t *)ctx;
size_t *matches = static_cast<size_t *>(ctx);
(*matches)++;
return 0; // continue matching
}
@@ -233,9 +232,8 @@ public:
}
// Valid TCP or UDP packet
const struct ip *iphdr = (const struct ip *)(pktData
+ sizeof(struct ether_header));
const char *payload = (const char *)pktData + offset;
const struct ip *iphdr = reinterpret_cast<const struct ip *>(pktData) + sizeof(struct ether_header);
const char *payload = reinterpret_cast<const char *>(pktData) + offset;
size_t id = stream_map.insert(std::make_pair(FiveTuple(iphdr),
stream_map.size())).first->second;
@@ -281,7 +279,7 @@ public:
// Close all open Hyperscan streams (potentially generating any
// end-anchored matches)
void closeStreams() {
for (auto &stream : streams) {
for (const auto &stream : streams) {
hs_error_t err = hs_close_stream(stream, scratch, onMatch,
&matchCount);
if (err != HS_SUCCESS) {
@@ -575,7 +573,7 @@ int main(int argc, char **argv) {
*/
static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset,
unsigned int *length) {
const ip *iph = (const ip *)(pkt_data + sizeof(ether_header));
const ip *iph = reinterpret_cast<const ip *>(pkt_data) + sizeof(ether_header);
const tcphdr *th = nullptr;
// Ignore packets that aren't IPv4
@@ -594,7 +592,7 @@ static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset,
switch (iph->ip_p) {
case IPPROTO_TCP:
th = (const tcphdr *)((const char *)iph + ihlen);
th = reinterpret_cast<const tcphdr *>(iph) + ihlen;
thlen = th->th_off * 4;
break;
case IPPROTO_UDP:

View File

@@ -67,7 +67,7 @@
* to pass in the pattern that was being searched for so we can print it out.
*/
static int eventHandler(unsigned int id, unsigned long long from,
unsigned long long to, unsigned int flags, void *ctx) {
unsigned long long to, unsigned int flags, void *ctx) { // cppcheck-suppress constParameterCallback
printf("Match for pattern \"%s\" at offset %llu\n", (char *)ctx, to);
return 0;
}
@@ -150,7 +150,7 @@ int main(int argc, char *argv[]) {
}
char *pattern = argv[1];
char *inputFN = argv[2];
const char *inputFN = argv[2];
/* First, we attempt to compile the pattern provided on the command line.
* We assume 'DOTALL' semantics, meaning that the '.' meta-character will