Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
pcre: "--with-pcre2"
maxminddb: "--with-maxminddb"
msan: "--with-sanitizer"
cflags: "-fno-sanitize-recover=all"
- compiler: "cc"
os: macOS-latest
pcre: "--with-pcre2"
Expand Down
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ AS_IF([test "${with_sanitizer+set}" = set],[
NDPI_LDFLAGS="${NDPI_LDFLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=leak"
#Sanitizers should work on any compilers that we support (or that we test on CI, at least)
#Exception: "-fsanitize=alignment" is not supported in gcc 4.9
AX_CHECK_COMPILE_FLAG([-fno-sanitize=alignment], [
NDPI_CFLAGS="${NDPI_CFLAGS} -fno-sanitize=alignment"
NDPI_LDFLAGS="${NDPI_LDFLAGS} -fno-sanitize=alignment"
AX_CHECK_COMPILE_FLAG([-fsanitize=alignment], [
NDPI_CFLAGS="${NDPI_CFLAGS} -fsanitize=alignment"
NDPI_LDFLAGS="${NDPI_LDFLAGS} -fsanitize=alignment"
])
])

Expand Down Expand Up @@ -302,7 +302,7 @@ echo "Setting API version to ${NDPI_API_VERSION}"
AC_DEFINE_UNQUOTED(NDPI_GIT_RELEASE, "${GIT_RELEASE}", [GIT Release])
AC_DEFINE_UNQUOTED(NDPI_GIT_DATE, "${GIT_DATE}", [Last GIT change])

NDPI_CFLAGS="-W -Wall -Wextra -Wno-address-of-packed-member ${NDPI_CFLAGS}"
NDPI_CFLAGS="-W -Wall -Wextra ${NDPI_CFLAGS}"

dnl> MacOS brew.sh
HOMEBREW_DIR=/opt/homebrew
Expand Down
5 changes: 4 additions & 1 deletion example/reader_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ typedef struct ndpi_flow_info {
} bfcp;
};

ndpi_serializer ndpi_flow_serializer;
struct {
uint8_t _alignment[4];
ndpi_serializer ndpi_flow_serializer;
};

char host_server_name[80]; /* Hostname/SNI */
char *server_hostname;
Expand Down
4 changes: 2 additions & 2 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ struct ndpi_binary_bitmap_entry {

typedef union
{
u_int32_t ipv4;
struct ndpi_in6_addr ipv6;
u_int32_t ipv4;
} ndpi_ip_addr_t;


Expand Down Expand Up @@ -2257,7 +2257,7 @@ typedef struct {
typedef ndpi_ranking_epoch_entry ndpi_ranking_change;

typedef struct {
u_int32_t epoch;
u_int64_t epoch;
ndpi_ranking_epoch_entry *entries;
} ndpi_ranking_epoch;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/ndpi_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ void ndpi_print_ranking(ndpi_ranking *rank) {
ndpi_ranking_epoch_entry *this_entries = (ndpi_ranking_epoch_entry*)&rank->epochs[i*epoch_len + sizeof(epoch->epoch)];
u_int32_t j;

fprintf(stdout, "\t[epoch %u @ %u]\n", i, epoch->epoch);
fprintf(stdout, "\t[epoch %u @ %llu]\n", i, (long long unsigned int)epoch->epoch);

for(j=0; j<rank->header.max_num_entries; j++) {
fprintf(stdout, "\t\t[%2d] %u - %llu\n", j,
Expand Down Expand Up @@ -2351,7 +2351,7 @@ u_int16_t ndpi_ranking_add_epoch(ndpi_ranking *rank,

qsort(entries, num_epoch_entries, sizeof(ndpi_ranking_epoch_entry), _comp);

epoch_len = (sizeof(ndpi_ranking_epoch_entry) * rank->header.max_num_entries) + sizeof(u_int32_t /* epoch */);
epoch_len = (sizeof(ndpi_ranking_epoch_entry) * rank->header.max_num_entries) + sizeof(this_epoch->epoch);
offset = epoch_len * rank->header.next_epoch_id;
this_epoch = (ndpi_ranking_epoch*)&rank->epochs[offset];

Expand Down
13 changes: 8 additions & 5 deletions src/lib/protocols/blizzard.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ static void search_blizzard_tcp(struct ndpi_detection_module_struct* ndpi_struct
}

/* Pattern found on Hearthstone */
if(packet->payload_packet_len >= 8 &&
le32toh(*(uint32_t *)&packet->payload[4]) == (u_int32_t)(packet->payload_packet_len - 8)) {
NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (Hearthstone)\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
return;
if(packet->payload_packet_len >= 8) {
uint32_t pdu_length;
memcpy(&pdu_length, &packet->payload[4], sizeof(pdu_length));
if (le32toh(pdu_length) == (u_int32_t)(packet->payload_packet_len - 8)) {
NDPI_LOG_INFO(ndpi_struct, "Found Blizzard (Hearthstone)\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BLIZZARD, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
return;
}
}

/* Pattern found on WoW */
Expand Down
14 changes: 11 additions & 3 deletions src/lib/protocols/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ static u_int16_t checkDNSSubprotocol(u_int16_t sport, u_int16_t dport) {
/* *********************************************** */

static u_int16_t get16(u_int *i, const u_int8_t *payload) {
u_int16_t v = *(u_int16_t*)&payload[*i];
u_int16_t v;

if (*i % 2 == 0)
v = *(u_int16_t*)&payload[*i];
else
memcpy(&v, &payload[*i], sizeof(v));

(*i) += 2;

Expand Down Expand Up @@ -383,7 +388,8 @@ static int process_answers(struct ndpi_detection_module_struct *ndpi_struct,
}

rsp_type = get16(&x, packet->payload);
rsp_ttl = ntohl(*((u_int32_t*)&packet->payload[x+2]));
memcpy(&rsp_ttl, &packet->payload[x+2], sizeof(rsp_ttl));
rsp_ttl = ntohl(rsp_ttl);

if(rsp_ttl == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_MINOR_ISSUES, "DNS Record with zero TTL");
Expand All @@ -400,7 +406,9 @@ static int process_answers(struct ndpi_detection_module_struct *ndpi_struct,

/* x points to the response "class" field */
if((x+12) <= packet->payload_packet_len) {
u_int32_t ttl = ntohl(*((u_int32_t*)&packet->payload[x+2]));
u_int32_t ttl;
memcpy(&ttl, &packet->payload[x+2], sizeof(ttl));
ttl = ntohl(ttl);

x += 6;
data_len = get16(&x, packet->payload);
Expand Down
14 changes: 8 additions & 6 deletions src/lib/protocols/mudfish.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ static void ndpi_search_mudfish(struct ndpi_detection_module_struct *ndpi_struct
}

// Check discovery response
if (packet->payload_packet_len > 8 &&
get_u_int32_t(packet->payload, 0) == htonl(0x554e2041) &&
get_u_int32_t(packet->payload, 0) == htonl(0x465f494e))
{
ndpi_int_mudfish_add_connection(ndpi_struct, flow);
return;
if (packet->payload_packet_len > 8) {
u_int32_t sig;
memcpy(&sig, &packet->payload[0], sizeof(sig));
if (sig == htonl(0x554e2041) && sig == htonl(0x465f494e))
{
ndpi_int_mudfish_add_connection(ndpi_struct, flow);
return;
}
}

NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
Expand Down
12 changes: 8 additions & 4 deletions src/lib/protocols/stun.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,14 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,

msg_type = ntohs(*((u_int16_t *)&payload[0]));
msg_len = ntohs(*((u_int16_t *)&payload[2]));
magic_cookie = ntohl(*((u_int32_t *)&payload[4]));
transaction_id[0] = ntohl(*((u_int32_t *)&payload[8]));
transaction_id[1] = ntohl(*((u_int32_t *)&payload[12]));
transaction_id[2] = ntohl(*((u_int32_t *)&payload[16]));
memcpy(&magic_cookie, &payload[4], sizeof(magic_cookie));
magic_cookie = ntohl(magic_cookie);
memcpy(&transaction_id[0], &payload[8], sizeof(transaction_id[0]));
transaction_id[0] = ntohl(transaction_id[0]);
memcpy(&transaction_id[1], &payload[12], sizeof(transaction_id[1]));
transaction_id[1] = ntohl(transaction_id[1]);
memcpy(&transaction_id[2], &payload[16], sizeof(transaction_id[2]));
transaction_id[2] = ntohl(transaction_id[2]);

/* No magic_cookie on classic-stun */
/* Let's hope that we don't have anymore classic-stun over TCP */
Expand Down
Loading