aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2024-02-09 19:19:03 +0100
committerGitHub <noreply@github.com>2024-02-09 19:19:03 +0100
commit03ecb026ff4d0e545cf21d463807b40265441bb3 (patch)
treefee3fca194dc2dd113e3b6dee782cc8b220f77e4 /src/lib
parentf5cec001f38f88cc0cdd8892dc6182dd8d7eafd0 (diff)
fuzz: improve fuzzing coverage (#2309)
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ndpi_main.c18
-rw-r--r--src/lib/ndpi_utils.c7
-rw-r--r--src/lib/protocols/jabber.c2
3 files changed, 15 insertions, 12 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 96c7e7cb5..d05032b57 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -2603,6 +2603,9 @@ ndpi_risk_enum ndpi_network_risk_ptree_match(struct ndpi_detection_module_struct
ndpi_prefix_t prefix;
ndpi_patricia_node_t *node;
+ if(!ndpi_str || !ndpi_str->ip_risk_ptree)
+ return(NDPI_NO_RISK);
+
/* Make sure all in network byte order otherwise compares wont work */
ndpi_fill_prefix_v4(&prefix, pin, 32, ((ndpi_patricia_tree_t *) ndpi_str->ip_risk_ptree)->maxbits);
node = ndpi_patricia_search_best(ndpi_str->ip_risk_ptree, &prefix);
@@ -4918,11 +4921,15 @@ int load_category_file_fd(struct ndpi_detection_module_struct *ndpi_str,
*/
int ndpi_load_categories_dir(struct ndpi_detection_module_struct *ndpi_str,
char *dir_path) {
- DIR *dirp = opendir(dir_path);
+ DIR *dirp;
struct dirent *dp;
int failed_files = 0;
int num_loaded = 0;
+ if(!ndpi_str || !dir_path)
+ return(0);
+
+ dirp = opendir(dir_path);
if (dirp == NULL)
return(0);
@@ -11102,9 +11109,12 @@ char *ndpi_get_config(struct ndpi_detection_module_struct *ndpi_str,
NDPI_LOG_DBG(ndpi_str, "Get [%s][%s]\n", proto, param);
for(c = &cfg_params[0]; c && c->param; c++) {
- if(((proto == NULL && c->proto == NULL) ||
- (proto && c->proto && strcmp(proto, c->proto) == 0)) &&
- strcmp(param, c->param) == 0) {
+ if((((proto == NULL && c->proto == NULL) ||
+ (proto && c->proto && strcmp(proto, c->proto) == 0)) &&
+ strcmp(param, c->param) == 0) ||
+ (proto && c->proto &&
+ strcmp(c->proto, "$PROTO_NAME_OR_ID") == 0 &&
+ strcmp(param, c->param) == 0)) {
return cfg_ops[c->type].fn_get((void *)((char *)&ndpi_str->cfg + c->offset), proto, buf, buf_len);
}
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index b80485c96..17e15b839 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -2955,13 +2955,8 @@ u_int8_t ndpi_check_flow_risk_exceptions(struct ndpi_detection_module_struct *nd
return(1);
break;
- case NDPI_MAX_RISK_PARAM_ID:
- /* Nothing to do, just avoid warnings */
- break;
-
default:
- printf("nDPI [%s:%u] Ignored risk parameter id %u\n",
- __FILE__, __LINE__, params[i].id);
+ NDPI_LOG_ERR(ndpi_str, "Ignored risk parameter id %u\n", params[i].id);
break;
}
}
diff --git a/src/lib/protocols/jabber.c b/src/lib/protocols/jabber.c
index 552d2618f..53ec251c5 100644
--- a/src/lib/protocols/jabber.c
+++ b/src/lib/protocols/jabber.c
@@ -53,8 +53,6 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
int i, left = packet->payload_packet_len-x;
- if(left <= 0) return;
-
for(i=0; jabber_strings[i].string != NULL; i++) {
if(ndpi_strnstr((const char*)&packet->payload[x], jabber_strings[i].string, left) != NULL) {
ndpi_int_jabber_add_connection(ndpi_struct, flow, jabber_strings[i].ndpi_protocol, NDPI_CONFIDENCE_DPI);