aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_main.h2
-rw-r--r--src/include/ndpi_typedefs.h1
-rw-r--r--src/lib/Makefile.in3
-rw-r--r--src/lib/ndpi_content_match.c.inc5
-rw-r--r--src/lib/ndpi_main.c92
-rw-r--r--src/lib/protocols/btlib.c5
-rw-r--r--src/lib/protocols/coap.c2
-rw-r--r--src/lib/protocols/csgo.c5
-rw-r--r--src/lib/protocols/directconnect.c1
-rw-r--r--src/lib/protocols/edonkey.c3
-rw-r--r--src/lib/protocols/ftp_data.c4
-rw-r--r--src/lib/protocols/gnutella.c1
-rw-r--r--src/lib/protocols/http.c2
-rw-r--r--src/lib/protocols/icecast.c2
-rw-r--r--src/lib/protocols/memcached.c3
15 files changed, 72 insertions, 59 deletions
diff --git a/src/include/ndpi_main.h b/src/include/ndpi_main.h
index e37576289..5ec98f6d9 100644
--- a/src/include/ndpi_main.h
+++ b/src/include/ndpi_main.h
@@ -124,7 +124,7 @@ extern "C" {
u_int8_t proto, u_int16_t sport, u_int16_t dport,
u_int8_t *user_defined_proto);
- extern u_int8_t ndpi_is_proto(ndpi_protocol p, u_int16_t proto);
+ extern u_int8_t ndpi_is_proto(ndpi_protocol proto, u_int16_t p);
extern u_int16_t ndpi_get_lower_proto(ndpi_protocol p);
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct,
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index fc80a675b..03f7bf6c3 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -360,6 +360,7 @@ typedef enum {
NDPI_HTTP_METHOD_OPTIONS,
NDPI_HTTP_METHOD_GET,
NDPI_HTTP_METHOD_HEAD,
+ NDPI_HTTP_METHOD_PATCH,
NDPI_HTTP_METHOD_POST,
NDPI_HTTP_METHOD_PUT,
NDPI_HTTP_METHOD_DELETE,
diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in
index cadd65ddd..65934502d 100644
--- a/src/lib/Makefile.in
+++ b/src/lib/Makefile.in
@@ -58,6 +58,9 @@ clean:
distclean: clean
/bin/rm -f Makefile
+cppcheck:
+ cppcheck --template='{file}:{line}:{severity}:{message}' --quiet --enable=all --force -I ../include *.c protocols/*.c
+
install: $(NDPI_LIBS)
mkdir -p $(DESTDIR)$(libdir)
cp $(NDPI_LIBS) $(DESTDIR)$(libdir)/
diff --git a/src/lib/ndpi_content_match.c.inc b/src/lib/ndpi_content_match.c.inc
index a060182d8..56afcb4f8 100644
--- a/src/lib/ndpi_content_match.c.inc
+++ b/src/lib/ndpi_content_match.c.inc
@@ -661,7 +661,12 @@ static ndpi_network host_protocol_list[] = {
{ 0x022E8A340 /* 34.232.163.64/28 */, 28, NDPI_PROTOCOL_VIBER },
{ 0x022F67200 /* 34.246.114.0/23 */, 23, NDPI_PROTOCOL_VIBER },
{ 0x3400FC00 /* 52.0.252.0/22 */, 22, NDPI_PROTOCOL_VIBER },
+ { 0x3403A746 /* 52.3.167.70/32 */, 32, NDPI_PROTOCOL_VIBER },
+ { 0x34162CEB /* 52.22.44.235/32 */, 32, NDPI_PROTOCOL_VIBER },
+ { 0x34165F0F /* 52.22.95.15/32 */, 32, NDPI_PROTOCOL_VIBER },
{ 0x3640BFF0 /* 54.64.191.240/28 */, 28, NDPI_PROTOCOL_VIBER },
+ { 0x3655545D /* 54.85.84.93/32 */, 32, NDPI_PROTOCOL_VIBER },
+ { 0x3655565D /* 54.85.86.93/32 */, 32, NDPI_PROTOCOL_VIBER },
{ 0x36A5FFD0 /* 54.165.255.208/28 */, 28, NDPI_PROTOCOL_VIBER },
{ 0x36A5FFE0 /* 54.165.255.224/27 */, 27, NDPI_PROTOCOL_VIBER },
{ 0x36DBBFA0 /* 54.219.191.160/28 */, 28, NDPI_PROTOCOL_VIBER },
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index fb764c730..6bd3d7eaa 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -545,7 +545,7 @@ ndpi_port_range * ndpi_build_default_ports_range(ndpi_port_range *ports,
ports[i].port_low = portB_low, ports[i].port_high = portB_high; i++;
ports[i].port_low = portC_low, ports[i].port_high = portC_high; i++;
ports[i].port_low = portD_low, ports[i].port_high = portD_high; i++;
- ports[i].port_low = portE_low, ports[i].port_high = portE_high; i++;
+ ports[i].port_low = portE_low, ports[i].port_high = portE_high;
return(ports);
}
@@ -564,7 +564,7 @@ ndpi_port_range * ndpi_build_default_ports(ndpi_port_range *ports,
ports[i].port_low = portB, ports[i].port_high = portB; i++;
ports[i].port_low = portC, ports[i].port_high = portC; i++;
ports[i].port_low = portD, ports[i].port_high = portD; i++;
- ports[i].port_low = portE, ports[i].port_high = portE; i++;
+ ports[i].port_low = portE, ports[i].port_high = portE;
return(ports);
}
@@ -718,8 +718,7 @@ static void addDefaultPort(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_proto_defaults_t *def,
u_int8_t customUserProto,
ndpi_default_ports_tree_node_t **root,
- const char *_func, int _line)
-{
+ const char *_func, int _line) {
ndpi_default_ports_tree_node_t *ret;
u_int16_t port;
@@ -2174,16 +2173,6 @@ u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_str
/* ******************************************* */
-/* u_int16_t ndpi_host_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t host /\* network byte order *\/) { */
-/* struct in_addr pin; */
-
-/* pin.s_addr = host; */
-
-/* return(ndpi_network_ptree_match(ndpi_struct, &pin)); */
-/* } */
-
-/* ******************************************* */
-
#if 0
static u_int8_t tor_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin) {
return((ndpi_network_ptree_match(ndpi_struct, pin) == NDPI_PROTOCOL_TOR) ? 1 : 0);
@@ -2380,7 +2369,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) {
for(i=0; i<NUM_CUSTOM_CATEGORIES; i++)
snprintf(ndpi_str->custom_category_labels[i],
- CUSTOM_CATEGORY_LABEL_LEN, "User custom category %u", i+1);
+ CUSTOM_CATEGORY_LABEL_LEN, "User custom category %u", (unsigned int)(i+1));
return ndpi_str;
}
@@ -2698,8 +2687,8 @@ u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_struc
struct ndpi_flow_struct *flow,
u_int8_t proto, u_int16_t sport, u_int16_t dport,
u_int8_t *user_defined_proto) {
-
*user_defined_proto = 0; /* Default */
+
if(sport && dport) {
ndpi_default_ports_tree_node_t *found = ndpi_get_guessed_protocol_id(ndpi_struct, proto, sport, dport);
@@ -2909,14 +2898,14 @@ int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, cons
fd = fopen(path, "r");
if(fd == NULL) {
- NDPI_LOG_ERR(ndpi_mod, "Unable to open file %s [%s]", path, strerror(errno));
+ NDPI_LOG_ERR(ndpi_mod, "Unable to open file %s [%s]\n", path, strerror(errno));
goto error;
}
buffer = ndpi_malloc(buffer_len);
if(buffer == NULL) {
- NDPI_LOG_ERR(ndpi_mod, "Memory allocation failure");
+ NDPI_LOG_ERR(ndpi_mod, "Memory allocation failure\n");
goto close_fd;
}
@@ -2933,7 +2922,7 @@ int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, cons
buffer = ndpi_realloc(old_buffer, old_buffer_len, buffer_len);
if(buffer == NULL) {
- NDPI_LOG_ERR(ndpi_mod, "Memory allocation failure");
+ NDPI_LOG_ERR(ndpi_mod, "Memory allocation failure\n");
free(old_buffer);
goto close_fd;
}
@@ -3023,8 +3012,7 @@ void ndpi_set_bitmask_protocol_detection(char * label,
/* ******************************************************************** */
void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
- const NDPI_PROTOCOL_BITMASK * dbm)
-{
+ const NDPI_PROTOCOL_BITMASK * dbm) {
NDPI_PROTOCOL_BITMASK detection_bitmask_local;
NDPI_PROTOCOL_BITMASK *detection_bitmask = &detection_bitmask_local;
u_int32_t a = 0;
@@ -3861,8 +3849,6 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
const struct ndpi_tcphdr *tcph = packet->tcp;
const struct ndpi_udphdr *udph = flow->packet.udp;
- u_int8_t proxy_enabled = 0;
-
packet->tcp_retransmission = 0, packet->packet_direction = 0;
if(ndpi_struct->direction_detect_disable) {
@@ -3907,7 +3893,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
flow->l4.tcp.seen_ack = 1;
}
if((flow->next_tcp_seq_nr[0] == 0 && flow->next_tcp_seq_nr[1] == 0)
- || (proxy_enabled && (flow->next_tcp_seq_nr[0] == 0 || flow->next_tcp_seq_nr[1] == 0))) {
+ || (flow->next_tcp_seq_nr[0] == 0 || flow->next_tcp_seq_nr[1] == 0)) {
/* initialize tcp sequence counters */
/* the ack flag needs to be set to get valid sequence numbers from the other
* direction. Usually it will catch the second packet syn+ack but it works
@@ -3919,9 +3905,8 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
if(tcph->ack != 0) {
flow->next_tcp_seq_nr[flow->packet.packet_direction] =
ntohl(tcph->seq) + (tcph->syn ? 1 : packet->payload_packet_len);
- if(!proxy_enabled) {
- flow->next_tcp_seq_nr[1 -flow->packet.packet_direction] = ntohl(tcph->ack_seq);
- }
+
+ flow->next_tcp_seq_nr[1 -flow->packet.packet_direction] = ntohl(tcph->ack_seq);
}
} else if(packet->payload_packet_len > 0) {
/* check tcp sequence counters */
@@ -4279,6 +4264,20 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
&& (flow->protos.stun_ssl.stun.num_processed_pkts > 0))
guessed_protocol_id = NDPI_PROTOCOL_STUN;
+
+ if(flow->host_server_name[0] != '\0') {
+ ndpi_protocol_match_result ret_match;
+
+ ndpi_match_host_subprotocol(ndpi_struct, flow,
+ (char *)flow->host_server_name,
+ strlen((const char*)flow->host_server_name),
+ &ret_match,
+ NDPI_PROTOCOL_DNS);
+
+ if(ret_match.protocol_id != NDPI_PROTOCOL_UNKNOWN)
+ guessed_host_protocol_id = ret_match.protocol_id;
+ }
+
ndpi_int_change_protocol(ndpi_struct, flow,
guessed_host_protocol_id,
guessed_protocol_id);
@@ -4433,18 +4432,8 @@ int ndpi_load_hostname_category(struct ndpi_detection_module_struct *ndpi_struct
struct hs_list *h = (struct hs_list*)malloc(sizeof(struct hs_list));
if(h) {
- char tmp[256];
int i, j;
- for(i=0, j=0; (j<sizeof(tmp)) && (name[i] != '\0'); i++) {
- if(name[i] == '.')
- tmp[j++] = '\\';
-
- tmp[j++] = name[i];
- }
-
- tmp[j] = '\0';
-
h->expression = ndpi_strdup(name), h->id = (unsigned int)category;
if(h->expression == NULL) {
free(h);
@@ -4507,7 +4496,8 @@ int ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_str)
ndpi_str->custom_categories.hostnames = (struct hs*)malloc(sizeof(struct hs));
if(ndpi_str->custom_categories.hostnames == NULL) {
- free(expressions), free(ids);
+ free(expressions);
+ free(ids);
return(-1); /* Failed */
}
@@ -4586,7 +4576,7 @@ int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_str
return 1;
}
}
-
+
ret->category = ndpi_get_proto_category(ndpi_struct, *ret);
return 0;
@@ -4599,7 +4589,7 @@ void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struc
ndpi_protocol *ret) {
if(ndpi_struct->custom_categories.categories_loaded) {
if(flow->guessed_header_category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED) {
- flow->category = flow->guessed_header_category;
+ flow->category = ret->category = flow->guessed_header_category;
return;
}
@@ -4731,7 +4721,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
flow->guessed_host_protocol_id = ndpi_guess_host_protocol_id(ndpi_struct, flow);
if(ndpi_struct->custom_categories.categories_loaded && flow->packet.iph) {
- ndpi_protocol ret;
+ ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
ndpi_fill_ip_protocol_category(ndpi_struct, flow->packet.iph->saddr, flow->packet.iph->daddr, &ret);
flow->guessed_header_category = ret.category;
@@ -4797,10 +4787,14 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
if(a != NDPI_PROTOCOL_UNKNOWN) {
int i;
- for(i=0; (i<sizeof(flow->host_server_name)) && (flow->host_server_name[i] != '\0'); i++)
- flow->host_server_name[i] = tolower(flow->host_server_name[i]);
-
- flow->host_server_name[i] ='\0';
+ for(i=0; i<sizeof(flow->host_server_name); i++) {
+ if(flow->host_server_name[i] != '\0')
+ flow->host_server_name[i] = tolower(flow->host_server_name[i]);
+ else {
+ flow->host_server_name[i] ='\0';
+ break;
+ }
+ }
}
ret_protocols:
@@ -5691,8 +5685,8 @@ char *ndpi_get_packet_dst_ip_string(struct ndpi_detection_module_struct *ndpi_st
/* ****************************************************** */
u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str,
- u_int16_t max_chars_to_read, u_int16_t * bytes_read)
-{
+ u_int16_t max_chars_to_read,
+ u_int16_t * bytes_read) {
u_int16_t val = ndpi_bytestream_to_number(str, max_chars_to_read, bytes_read);
return ntohs(val);
}
@@ -6107,7 +6101,7 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
u_int16_t master_protocol_id,
ndpi_protocol_match_result *ret_match,
u_int8_t is_host_match) {
- int matching_protocol_id = NDPI_PROTOCOL_UNKNOWN;
+ int matching_protocol_id;
struct ndpi_packet_struct *packet = &flow->packet;
#ifndef HAVE_HYPERSCAN
@@ -6117,6 +6111,8 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
#else
struct hs *hs = (struct hs*)ndpi_struct->hyperscan;
hs_error_t status;
+
+ matching_protocol_id = NDPI_PROTOCOL_UNKNOWN;
/*
TODO HYPERSCAN
In case of match fill up ret_match and set flow protocol + category
diff --git a/src/lib/protocols/btlib.c b/src/lib/protocols/btlib.c
index 5992c1b28..ea06a6348 100644
--- a/src/lib/protocols/btlib.c
+++ b/src/lib/protocols/btlib.c
@@ -204,8 +204,7 @@ void cb_data(bt_parse_data_cb_t *cbd,int *ret) {
if(cbd->t == 0) return;
if(cbd->t == 1) {
-
- DEBUG_TRACE(printf("%s %lld\n",cbd->buf,cbd->v.i));
+ DEBUG_TRACE(printf("%s %lld\n",cbd->buf, (long long)cbd->v.i));
if(STREQ(cbd->buf,"a.port")) {
p->a.port = (u_int16_t)(cbd->v.i & 0xffff);
@@ -234,7 +233,7 @@ void cb_data(bt_parse_data_cb_t *cbd,int *ret) {
p->h_mint = 1;
return;
}
- DEBUG_TRACE(printf("UNKNOWN %s %lld\n",cbd->buf,cbd->v.i));
+ DEBUG_TRACE(printf("UNKNOWN %s %lld\n",cbd->buf, (long long)cbd->v.i));
return;
}
if(cbd->t != 2) {
diff --git a/src/lib/protocols/coap.c b/src/lib/protocols/coap.c
index cf5061bbe..c99ab5fc1 100644
--- a/src/lib/protocols/coap.c
+++ b/src/lib/protocols/coap.c
@@ -130,7 +130,7 @@ void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
if(h->version == 1) {
if(h->type == CON || h->type == NO_CON || h->type == ACK || h->type == RST ) {
if(h->tkl < 8) {
- if((h->code >= 0 && h->code <= 5) || (h->code >= 65 && h->code <= 69) ||
+ if((/* h->code >= 0 && */ h->code <= 5) || (h->code >= 65 && h->code <= 69) ||
(h->code >= 128 && h->code <= 134) || (h->code >= 140 && h->code <= 143) ||
(h->code >= 160 && h->code <= 165)) {
diff --git a/src/lib/protocols/csgo.c b/src/lib/protocols/csgo.c
index 7f4479419..f316f96b7 100644
--- a/src/lib/protocols/csgo.c
+++ b/src/lib/protocols/csgo.c
@@ -30,6 +30,11 @@ void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct n
struct ndpi_packet_struct* packet = &flow->packet;
if (packet->udp != NULL) {
+ if (packet->payload_packet_len < sizeof(uint32_t)) {
+ NDPI_LOG_DBG2(ndpi_struct, "Short csgo packet\n");
+ return;
+ }
+
uint32_t w = htonl(get_u_int32_t(packet->payload, 0));
NDPI_LOG_DBG2(ndpi_struct, "CSGO: word %08x\n", w);
diff --git a/src/lib/protocols/directconnect.c b/src/lib/protocols/directconnect.c
index 5088685e4..19582724d 100644
--- a/src/lib/protocols/directconnect.c
+++ b/src/lib/protocols/directconnect.c
@@ -318,7 +318,6 @@ static void ndpi_search_directconnect_udp(struct ndpi_detection_module_struct
struct ndpi_id_struct *dst = flow->dst;
int pos, count = 0;
-
if (dst != NULL && dst->detected_directconnect_udp_port == packet->udp->dest) {
if ((u_int32_t)
(packet->tick_timestamp -
diff --git a/src/lib/protocols/edonkey.c b/src/lib/protocols/edonkey.c
index 547bafc5f..ca5abebad 100644
--- a/src/lib/protocols/edonkey.c
+++ b/src/lib/protocols/edonkey.c
@@ -177,7 +177,6 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->edonkey_stage = packet->packet_direction + 1;
}
-
} else {
NDPI_LOG_DBG2(ndpi_struct, "EDONKEY stage %u: \n", flow->edonkey_stage);
@@ -187,7 +186,7 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
}
/* This is a packet in another direction. Check if we find the proper response. */
- if((payload_len == 0) || (ndpi_edonkey_payload_check(packet->payload, payload_len))) {
+ if(ndpi_edonkey_payload_check(packet->payload, payload_len)) {
NDPI_LOG_INFO(ndpi_struct, "found EDONKEY\n");
ndpi_int_edonkey_add_connection(ndpi_struct, flow);
} else {
diff --git a/src/lib/protocols/ftp_data.c b/src/lib/protocols/ftp_data.c
index 7c646c363..3aaf6f97e 100644
--- a/src/lib/protocols/ftp_data.c
+++ b/src/lib/protocols/ftp_data.c
@@ -62,9 +62,11 @@ static int ndpi_match_ftp_data_directory(struct ndpi_detection_module_struct *nd
;
} else
return 0;
+
+ return 1;
}
- return 1;
+ return 0;
}
static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
diff --git a/src/lib/protocols/gnutella.c b/src/lib/protocols/gnutella.c
index 5bc2980cc..75a8e534b 100644
--- a/src/lib/protocols/gnutella.c
+++ b/src/lib/protocols/gnutella.c
@@ -68,7 +68,6 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
-
u_int16_t c;
NDPI_LOG_DBG(ndpi_struct, "search GNUTELLA\n");
diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c
index 33ef9e2ed..e715dd499 100644
--- a/src/lib/protocols/http.c
+++ b/src/lib/protocols/http.c
@@ -184,6 +184,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
case 'P':
switch(flow->packet.http_method.ptr[1]) {
+ case 'A': flow->http.method = NDPI_HTTP_METHOD_PATCH; break;
case 'O': flow->http.method = NDPI_HTTP_METHOD_POST; break;
case 'U': flow->http.method = NDPI_HTTP_METHOD_PUT; break;
}
@@ -414,6 +415,7 @@ static struct l_string {
STATIC_STRING_L("OPTIONS "),
STATIC_STRING_L("HEAD "),
STATIC_STRING_L("PUT "),
+ STATIC_STRING_L("PATCH "),
STATIC_STRING_L("DELETE "),
STATIC_STRING_L("CONNECT "),
STATIC_STRING_L("PROPFIND "),
diff --git a/src/lib/protocols/icecast.c b/src/lib/protocols/icecast.c
index 515d5b572..0bb87b88a 100644
--- a/src/lib/protocols/icecast.c
+++ b/src/lib/protocols/icecast.c
@@ -64,6 +64,8 @@ void ndpi_search_icecast_tcp(struct ndpi_detection_module_struct *ndpi_struct, s
goto icecast_exclude;
}
+ if(flow == NULL) return;
+
if((packet->packet_direction == flow->setup_packet_direction)
&& (flow->packet_counter < 10)) {
return;
diff --git a/src/lib/protocols/memcached.c b/src/lib/protocols/memcached.c
index e9deb5cc9..44a8b0858 100644
--- a/src/lib/protocols/memcached.c
+++ b/src/lib/protocols/memcached.c
@@ -89,7 +89,7 @@
#define MEMCACHED_MIN_MATCH 2 /* Minimum number of command/responses required */
-#define MEMCACHED_MATCH(cr) memcmp(offset, cr, cr ## _LEN)
+#define MEMCACHED_MATCH(cr) (cr ## _LEN > length || memcmp(offset, cr, cr ## _LEN))
static void ndpi_int_memcached_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
@@ -105,6 +105,7 @@ void ndpi_search_memcached(
{
struct ndpi_packet_struct *packet = &flow->packet;
const u_int8_t *offset = packet->payload;
+ const u_int16_t length = packet->payload_packet_len;
u_int8_t *matches;
NDPI_LOG_DBG(ndpi_struct, "search memcached\n");