fuzz: fix memory allocation failure logic (#1867)
We *do* want to have some allocation errors.
Fix some related bugs
Fix: 29be01ef
This commit is contained in:
+37
-3
@@ -2789,10 +2789,26 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
||||
ndpi_str->ndpi_num_custom_protocols = 0;
|
||||
|
||||
ndpi_str->host_automa.ac_automa = ac_automata_init(ac_domain_match_handler);
|
||||
if(!ndpi_str->host_automa.ac_automa) {
|
||||
ndpi_exit_detection_module(ndpi_str);
|
||||
return(NULL);
|
||||
}
|
||||
ndpi_str->host_risk_mask_automa.ac_automa = ac_automata_init(ac_domain_match_handler);
|
||||
if(!ndpi_str->host_risk_mask_automa.ac_automa) {
|
||||
ndpi_exit_detection_module(ndpi_str);
|
||||
return(NULL);
|
||||
}
|
||||
ndpi_str->common_alpns_automa.ac_automa = ac_automata_init(ac_domain_match_handler);
|
||||
if(!ndpi_str->common_alpns_automa.ac_automa) {
|
||||
ndpi_exit_detection_module(ndpi_str);
|
||||
return(NULL);
|
||||
}
|
||||
load_common_alpns(ndpi_str);
|
||||
ndpi_str->tls_cert_subject_automa.ac_automa = ac_automata_init(NULL);
|
||||
if(!ndpi_str->tls_cert_subject_automa.ac_automa) {
|
||||
ndpi_exit_detection_module(ndpi_str);
|
||||
return(NULL);
|
||||
}
|
||||
ndpi_str->malicious_ja3_hashmap = NULL; /* Initialized on demand */
|
||||
ndpi_str->malicious_sha1_hashmap = NULL; /* Initialized on demand */
|
||||
ndpi_str->risky_domain_automa.ac_automa = NULL; /* Initialized on demand */
|
||||
@@ -2806,7 +2822,15 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
||||
}
|
||||
|
||||
ndpi_str->custom_categories.hostnames.ac_automa = ac_automata_init(ac_domain_match_handler);
|
||||
if(!ndpi_str->custom_categories.hostnames.ac_automa) {
|
||||
ndpi_exit_detection_module(ndpi_str);
|
||||
return(NULL);
|
||||
}
|
||||
ndpi_str->custom_categories.hostnames_shadow.ac_automa = ac_automata_init(ac_domain_match_handler);
|
||||
if(!ndpi_str->custom_categories.hostnames_shadow.ac_automa) {
|
||||
ndpi_exit_detection_module(ndpi_str);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ndpi_str->custom_categories.ipAddresses = ndpi_patricia_new(32 /* IPv4 */);
|
||||
ndpi_str->custom_categories.ipAddresses_shadow = ndpi_patricia_new(32 /* IPv4 */);
|
||||
@@ -3859,6 +3883,9 @@ int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str,
|
||||
FILE *fd;
|
||||
int len, num = 0;
|
||||
|
||||
if(!ndpi_str || !path)
|
||||
return(-1);
|
||||
|
||||
fd = fopen(path, "r");
|
||||
|
||||
if(fd == NULL) {
|
||||
@@ -3933,6 +3960,9 @@ int ndpi_load_risk_domain_file(struct ndpi_detection_module_struct *ndpi_str, co
|
||||
FILE *fd;
|
||||
int len, num = 0;
|
||||
|
||||
if(!ndpi_str || !path)
|
||||
return(-1);
|
||||
|
||||
fd = fopen(path, "r");
|
||||
|
||||
if(fd == NULL) {
|
||||
@@ -3978,7 +4008,7 @@ int ndpi_load_malicious_ja3_file(struct ndpi_detection_module_struct *ndpi_str,
|
||||
FILE *fd;
|
||||
int len, num = 0;
|
||||
|
||||
if(!ndpi_str)
|
||||
if(!ndpi_str || !path)
|
||||
return(-1);
|
||||
if(ndpi_str->malicious_ja3_hashmap == NULL && ndpi_hash_init(&ndpi_str->malicious_ja3_hashmap) != 0)
|
||||
return(-1);
|
||||
@@ -4042,7 +4072,7 @@ int ndpi_load_malicious_sha1_file(struct ndpi_detection_module_struct *ndpi_str,
|
||||
size_t i, len;
|
||||
int num = 0;
|
||||
|
||||
if(!ndpi_str)
|
||||
if(!ndpi_str || !path)
|
||||
return(-1);
|
||||
if(ndpi_str->malicious_sha1_hashmap == NULL && ndpi_hash_init(&ndpi_str->malicious_sha1_hashmap) != 0)
|
||||
return(-1);
|
||||
@@ -4113,6 +4143,9 @@ int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_str, cons
|
||||
int chunk_len = 1024, buffer_len = chunk_len, old_buffer_len;
|
||||
int i, rc = -1;
|
||||
|
||||
if(!ndpi_str || !path)
|
||||
return(-1);
|
||||
|
||||
fd = fopen(path, "r");
|
||||
|
||||
if(fd == NULL) {
|
||||
@@ -7945,7 +7978,8 @@ int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_str, char *pr
|
||||
int i;
|
||||
|
||||
for(i = 0; i < (int) ndpi_str->ndpi_num_supported_protocols; i++)
|
||||
if(strcasecmp(proto, ndpi_str->proto_defaults[i].protoName) == 0)
|
||||
if(ndpi_str->proto_defaults[i].protoName &&
|
||||
strcasecmp(proto, ndpi_str->proto_defaults[i].protoName) == 0)
|
||||
return(i);
|
||||
|
||||
return(-1);
|
||||
|
||||
Reference in New Issue
Block a user