aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2018-09-13 00:11:09 +0200
committerLuca Deri <deri@ntop.org>2018-09-13 00:11:09 +0200
commit51fdd12d235e6c81eb0b48ec7acd4aeb02c3a3c2 (patch)
tree8c02439dfe5d61780c6aee5afc7fa0ce60722887
parente8c738282d99f4bcb056d81211e331ca9db8d7bf (diff)
parent24110acafcc143bfdc66ef868ef26bd03adead75 (diff)
Merge branch 'dev' of https://github.com/ntop/nDPI into dev
-rw-r--r--src/lib/ndpi_main.c9
-rw-r--r--src/lib/protocols/spotify.c28
2 files changed, 23 insertions, 14 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 722fdb68f..b904bbefc 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -4641,7 +4641,11 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
packet->line[packet->parsed_lines].ptr = packet->payload;
packet->line[packet->parsed_lines].len = 0;
- for(a = 0; a < packet->payload_packet_len-2; a++) {
+ for(a = 0; a < packet->payload_packet_len; a++) {
+
+ if((a + 1) == packet->payload_packet_len)
+ return; /* Return if only one byte remains (prevent invalid reads past end-of-buffer) */
+
if(get_u_int16_t(packet->payload, a) == ntohs(0x0d0a)) { /* If end of line char sequence CR+NL "\r\n", process line */
packet->line[packet->parsed_lines].len = (u_int16_t)(((unsigned long) &packet->payload[a]) - ((unsigned long) packet->line[packet->parsed_lines].ptr));
@@ -4821,9 +4825,6 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
packet->line[packet->parsed_lines].ptr = &packet->payload[a + 2];
packet->line[packet->parsed_lines].len = 0;
- if((a + 2) >= packet->payload_packet_len)
- return;
-
a++; /* next char in the payload */
}
}
diff --git a/src/lib/protocols/spotify.c b/src/lib/protocols/spotify.c
index 699d8f346..a180a1ea7 100644
--- a/src/lib/protocols/spotify.c
+++ b/src/lib/protocols/spotify.c
@@ -88,17 +88,25 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
*/
//printf("%08X - %08X\n", ntohl(packet->iph->saddr), ntohl(packet->iph->daddr));
- if(((ntohl(packet->iph->saddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0x4E1F0800 /* 78.31.8.0 */)
- || ((ntohl(packet->iph->daddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0x4E1F0800 /* 78.31.8.0 */)
+
+ long src_addr = ntohl(packet->iph->saddr);
+ long dst_addr = ntohl(packet->iph->daddr);
+ long src_addr_masked_22 = src_addr & 0xFFFFFC00; // */22
+ long dst_addr_masked_22 = dst_addr & 0xFFFFFC00; // */22
+ long src_addr_masked_24 = src_addr & 0xFFFFFF00; // */24
+ long dst_addr_masked_24 = dst_addr & 0xFFFFFF00; // */24
+
+ if( src_addr_masked_22 == 0x4E1F0800 /* 78.31.8.0 */
+ || dst_addr_masked_22 == 0x4E1F0800 /* 78.31.8.0 */
/* **** */
- || ((ntohl(packet->iph->saddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0xC1EBE800 /* 193.235.232.0 */)
- || ((ntohl(packet->iph->daddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0xC1EBE800 /* 193.235.232.0 */)
- /* **** */
- || ((ntohl(packet->iph->saddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0xC284C400 /* 194.132.196.0 */)
- || ((ntohl(packet->iph->daddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0xC284C400 /* 194.132.196.0 */)
- /* **** */
- || ((ntohl(packet->iph->saddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0xC284A200 /* 194.132.162.0 */)
- || ((ntohl(packet->iph->daddr) & 0xFFFFFC00 /* 255.255.252.0 */) == 0xC284A200 /* 194.132.162.0 */)
+ || src_addr_masked_22 == 0xC1EBE800 /* 193.235.232.0 */
+ || dst_addr_masked_22 == 0xC1EBE800 /* 193.235.232.0 */
+ /* **** */
+ || src_addr_masked_22 == 0xC284C400 /* 194.132.196.0 */
+ || dst_addr_masked_22 == 0xC284C400 /* 194.132.196.0 */
+ /* **** */
+ || src_addr_masked_24 == 0xC284A200 /* 194.132.162.0 */
+ || dst_addr_masked_24 == 0xC284A200 /* 194.132.162.0 */
) {
NDPI_LOG_INFO(ndpi_struct, "found spotify via ip range\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SPOTIFY, NDPI_PROTOCOL_UNKNOWN);