aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ndpi_analyze.c83
-rw-r--r--src/lib/ndpi_content_match.c.inc2
-rw-r--r--src/lib/ndpi_main.c5
-rw-r--r--src/lib/protocols/tls.c14
4 files changed, 99 insertions, 5 deletions
diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c
index 2d7e11abc..e1f37cc8d 100644
--- a/src/lib/ndpi_analyze.c
+++ b/src/lib/ndpi_analyze.c
@@ -233,3 +233,86 @@ void ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) {
double ndpi_hll_count(struct ndpi_hll *hll) {
return(hll_count(hll));
}
+
+/* ********************************************************************************* */
+/* ********************************************************************************* */
+
+int ndpi_init_bin(struct ndpi_bin *b, enum ndpi_bin_family f, u_int8_t num_bins) {
+ b->num_bins = num_bins, b->family = f, b->num_incs = 0;
+
+ switch(f) {
+ case ndpi_bin_family8:
+ if((b->u.bins8 = (u_int8_t*)calloc(num_bins, sizeof(u_int8_t))) == NULL)
+ return(-1);
+ break;
+
+ case ndpi_bin_family16:
+ if((b->u.bins16 = (u_int16_t*)calloc(num_bins, sizeof(u_int16_t))) == NULL)
+ return(-1);
+ break;
+
+ case ndpi_bin_family32:
+ if((b->u.bins32 = (u_int32_t*)calloc(num_bins, sizeof(u_int32_t))) == NULL)
+ return(-1);
+ break;
+ }
+
+ return(0);
+}
+
+void ndpi_free_bin(struct ndpi_bin *b) {
+ switch(b->family) {
+ case ndpi_bin_family8:
+ free(b->u.bins8);
+ break;
+ case ndpi_bin_family16:
+ free(b->u.bins16);
+ break;
+ case ndpi_bin_family32:
+ free(b->u.bins32);
+ break;
+ }
+}
+
+void ndpi_inc_bin(struct ndpi_bin *b, u_int8_t slot_id) {
+ if(slot_id >= b->num_bins) slot_id = 0;
+
+ b->num_incs += 1;
+
+ switch(b->family) {
+ case ndpi_bin_family8:
+ b->u.bins8[slot_id]++;
+ break;
+ case ndpi_bin_family16:
+ b->u.bins16[slot_id]++;
+ break;
+ case ndpi_bin_family32:
+ b->u.bins32[slot_id]++;
+ break;
+ }
+}
+
+/*
+ Each bin slot is transformed in a % with respect to the value total
+ */
+void ndpi_normalize_bin(struct ndpi_bin *b) {
+ u_int8_t i;
+
+ if(b->num_incs == 0) return;
+
+ switch(b->family) {
+ case ndpi_bin_family8:
+ for(i=0; i<b->num_bins; i++)
+ b->u.bins8[i] = (b->u.bins8[i]*100) / b->num_incs;
+ break;
+ case ndpi_bin_family16:
+ for(i=0; i<b->num_bins; i++)
+ b->u.bins16[i] = (b->u.bins16[i]*100) / b->num_incs;
+ break;
+ case ndpi_bin_family32:
+ for(i=0; i<b->num_bins; i++)
+ b->u.bins32[i] = (b->u.bins32[i]*100) / b->num_incs;
+ break;
+ }
+}
+
diff --git a/src/lib/ndpi_content_match.c.inc b/src/lib/ndpi_content_match.c.inc
index 7828c50f7..eec1156dd 100644
--- a/src/lib/ndpi_content_match.c.inc
+++ b/src/lib/ndpi_content_match.c.inc
@@ -9277,6 +9277,7 @@ static const char *ndpi_en_bigrams[] = {
/* ******************************************************************** */
+#if 0
static const char *ndpi_en_popular_bigrams[] = {
"th", "he", "in", "er", "an", "re", "on", "at", "en", "nd", "ti", "es", "or", "te", "of", "ed", "is", "it",
"al", "ar", "st", "to", "nt", "ng", "se", "ha", "as", "ou", "io", "le", "ve", "co", "me", "de", "hi", "ri",
@@ -9317,6 +9318,7 @@ static const char *ndpi_en_popular_bigrams[] = {
"gq", "vk", "zj", "xk", "qp", "hx", "fz", "qh", "qj", "jz", "vq", "kq", "xd", "qw", "jx", "qx", "kz", "wx",
"fq", "xz", "zx", "jq", "qg", "qk", "qy", "qz", "wq", "wz", NULL
};
+#endif
/* ******************************************************************** */
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index a44107679..7799db0c1 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -131,7 +131,7 @@ void *ndpi_realloc(void *ptr, size_t old_size, size_t new_size) {
/* ****************************************** */
char *ndpi_strdup(const char *s) {
- if( s == NULL ){
+ if(s == NULL ){
return NULL;
}
@@ -4336,7 +4336,8 @@ static void ndpi_reset_packet_line_info(struct ndpi_packet_struct *packet) {
packet->accept_line.len = 0, packet->user_agent_line.ptr = NULL, packet->user_agent_line.len = 0,
packet->http_url_name.ptr = NULL, packet->http_url_name.len = 0, packet->http_encoding.ptr = NULL,
packet->http_encoding.len = 0, packet->http_transfer_encoding.ptr = NULL, packet->http_transfer_encoding.len = 0,
- packet->http_contentlen.ptr = NULL, packet->http_contentlen.len = 0, packet->http_cookie.ptr = NULL,
+ packet->http_contentlen.ptr = NULL, packet->http_contentlen.len = 0, packet->content_disposition_line.ptr = NULL,
+ packet->content_disposition_line.len = 0, packet->http_cookie.ptr = NULL,
packet->http_cookie.len = 0, packet->http_origin.len = 0, packet->http_origin.ptr = NULL,
packet->http_x_session_type.ptr = NULL, packet->http_x_session_type.len = 0, packet->server_line.ptr = NULL,
packet->server_line.len = 0, packet->http_method.ptr = NULL, packet->http_method.len = 0,
diff --git a/src/lib/protocols/tls.c b/src/lib/protocols/tls.c
index 816b23a50..eac9e0f77 100644
--- a/src/lib/protocols/tls.c
+++ b/src/lib/protocols/tls.c
@@ -196,6 +196,14 @@ static int extractRDNSequence(struct ndpi_packet_struct *packet,
char *str;
u_int len, j;
+ if (*rdnSeqBuf_offset >= rdnSeqBuf_len) {
+#ifdef DEBUG_TLS
+ printf("[TLS] %s() [buffer capacity reached][%u]\n",
+ __FUNCTION__, rdnSeqBuf_len);
+#endif
+ return -1;
+ }
+
// packet is truncated... further inspection is not needed
if((offset+4+str_len) >= packet->payload_packet_len)
return(-1);
@@ -235,7 +243,7 @@ static void processCertificateElements(struct ndpi_detection_module_struct *ndpi
u_int16_t p_offset, u_int16_t certificate_len) {
struct ndpi_packet_struct *packet = &flow->packet;
u_int num_found = 0, i;
- char buffer[64] = { '\0' }, rdnSeqBuf[1024] = { '\0' };
+ char buffer[64] = { '\0' }, rdnSeqBuf[2048] = { '\0' };
u_int rdn_len = 0;
#ifdef DEBUG_TLS
@@ -1200,14 +1208,14 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
printf("Client SSL [ALPN: %u]\n", alpn_len);
#endif
- if((alpn_str_len+alpn_len+1) < sizeof(alpn_str)) {
+ if((alpn_str_len+alpn_len+1) < (sizeof(alpn_str)-1)) {
if(alpn_str_len > 0) {
alpn_str[alpn_str_len] = ',';
alpn_str_len++;
}
for(alpn_i=0; alpn_i<alpn_len; alpn_i++)
- alpn_str[alpn_str_len+alpn_i] = packet->payload[s_offset+alpn_i];
+ alpn_str[alpn_str_len+alpn_i] = packet->payload[s_offset+alpn_i];
s_offset += alpn_len, alpn_str_len += alpn_len;;
} else