Added memory checks
This commit is contained in:
+11
-5
@@ -80,11 +80,17 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|||||||
|
|
||||||
r = pcap_next_ex(pkts, &header, &pkt);
|
r = pcap_next_ex(pkts, &header, &pkt);
|
||||||
while (r > 0) {
|
while (r > 0) {
|
||||||
/* allocate an exact size buffer to check overflows */
|
if(header->caplen >= 42 /* ARP+ size */) {
|
||||||
uint8_t *packet_checked = malloc(header->caplen);
|
/* allocate an exact size buffer to check overflows */
|
||||||
memcpy(packet_checked, pkt, header->caplen);
|
uint8_t *packet_checked = malloc(header->caplen);
|
||||||
ndpi_workflow_process_packet(workflow, header, packet_checked, NULL);
|
|
||||||
free(packet_checked);
|
if(packet_checked) {
|
||||||
|
memcpy(packet_checked, pkt, header->caplen);
|
||||||
|
ndpi_workflow_process_packet(workflow, header, packet_checked, NULL);
|
||||||
|
free(packet_checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r = pcap_next_ex(pkts, &header, &pkt);
|
r = pcap_next_ex(pkts, &header, &pkt);
|
||||||
}
|
}
|
||||||
ndpi_workflow_free(workflow);
|
ndpi_workflow_free(workflow);
|
||||||
|
|||||||
+20
-18
@@ -114,7 +114,7 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
quic_hlen++;
|
quic_hlen++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(udp_len > quic_hlen + 16 + 4) {
|
if(udp_len > (quic_hlen + 16 + 4)) {
|
||||||
if(!strncmp((char*)&packet->payload[quic_hlen+16], "CHLO" /* Client Hello */, 4)) {
|
if(!strncmp((char*)&packet->payload[quic_hlen+16], "CHLO" /* Client Hello */, 4)) {
|
||||||
/* Check if SNI (Server Name Identification) is present */
|
/* Check if SNI (Server Name Identification) is present */
|
||||||
for(i=quic_hlen+12; i<udp_len-3; i++) {
|
for(i=quic_hlen+12; i<udp_len-3; i++) {
|
||||||
@@ -126,31 +126,33 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
u_int32_t prev_offset = (*((u_int32_t*)&packet->payload[i-4]));
|
u_int32_t prev_offset = (*((u_int32_t*)&packet->payload[i-4]));
|
||||||
|
|
||||||
if(offset > prev_offset) {
|
if(offset > prev_offset) {
|
||||||
u_int32_t len = offset-prev_offset;
|
u_int32_t len = offset - prev_offset;
|
||||||
u_int32_t sni_offset = i+prev_offset+1;
|
u_int32_t sni_offset = i+prev_offset+1;
|
||||||
|
|
||||||
while((sni_offset < udp_len) && (packet->payload[sni_offset] == '-'))
|
if(len < udp_len) {
|
||||||
sni_offset++;
|
while((sni_offset < udp_len) && (packet->payload[sni_offset] == '-'))
|
||||||
|
sni_offset++;
|
||||||
|
|
||||||
if(len > 0 && (sni_offset+len) < udp_len) {
|
if((sni_offset+len) < udp_len) {
|
||||||
u_int32_t max_len = sizeof(flow->host_server_name)-1, j = 0;
|
u_int32_t max_len = sizeof(flow->host_server_name)-1, j = 0;
|
||||||
ndpi_protocol_match_result ret_match;
|
ndpi_protocol_match_result ret_match;
|
||||||
|
|
||||||
if(len > max_len) len = max_len;
|
if(len > max_len) len = max_len;
|
||||||
|
|
||||||
while((len > 0) && (sni_offset < udp_len)) {
|
while((len > 0) && (sni_offset < udp_len)) {
|
||||||
flow->host_server_name[j++] = packet->payload[sni_offset];
|
flow->host_server_name[j++] = packet->payload[sni_offset];
|
||||||
sni_offset++, len--;
|
sni_offset++, len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
ndpi_match_host_subprotocol(ndpi_struct, flow,
|
||||||
|
(char *)flow->host_server_name,
|
||||||
|
strlen((const char*)flow->host_server_name),
|
||||||
|
&ret_match,
|
||||||
|
NDPI_PROTOCOL_QUIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndpi_match_host_subprotocol(ndpi_struct, flow,
|
break;
|
||||||
(char *)flow->host_server_name,
|
|
||||||
strlen((const char*)flow->host_server_name),
|
|
||||||
&ret_match,
|
|
||||||
NDPI_PROTOCOL_QUIC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -479,7 +479,8 @@ static void processCertificateElements(struct ndpi_detection_module_struct *ndpi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rdn_len) flow->protos.stun_ssl.ssl.subjectDN = ndpi_strdup(rdnSeqBuf);
|
if(rdn_len && (flow->protos.stun_ssl.ssl.subjectDN == NULL))
|
||||||
|
flow->protos.stun_ssl.ssl.subjectDN = ndpi_strdup(rdnSeqBuf);
|
||||||
|
|
||||||
if(flow->protos.stun_ssl.ssl.subjectDN && flow->protos.stun_ssl.ssl.issuerDN
|
if(flow->protos.stun_ssl.ssl.subjectDN && flow->protos.stun_ssl.ssl.issuerDN
|
||||||
&& (!strcmp(flow->protos.stun_ssl.ssl.subjectDN, flow->protos.stun_ssl.ssl.issuerDN)))
|
&& (!strcmp(flow->protos.stun_ssl.ssl.subjectDN, flow->protos.stun_ssl.ssl.issuerDN)))
|
||||||
|
|||||||
Reference in New Issue
Block a user