[PATCH]handle matcher NULL pointer

This commit is contained in:
liuwentan
2023-06-20 17:34:46 +08:00
parent 8ad355d5d7
commit 7cb24d96f8
9 changed files with 48 additions and 25 deletions

View File

@@ -428,13 +428,23 @@ int maat_get_table_id(struct maat *maat_inst, const char *table_name)
return table_id; return table_id;
} }
static inline void maat_runtime_ref_inc(struct maat_runtime *maat_rt, int thread_id) static inline void maat_runtime_ref_inc(struct maat_runtime *maat_rt,
int thread_id)
{ {
if (NULL == maat_rt) {
return;
}
alignment_int64_array_add(maat_rt->ref_cnt, thread_id, 1); alignment_int64_array_add(maat_rt->ref_cnt, thread_id, 1);
} }
static inline void maat_runtime_ref_dec(struct maat_runtime *maat_rt, int thread_id) static inline void maat_runtime_ref_dec(struct maat_runtime *maat_rt,
int thread_id)
{ {
if (NULL == maat_rt) {
return;
}
alignment_int64_array_add(maat_rt->ref_cnt, thread_id, -1); alignment_int64_array_add(maat_rt->ref_cnt, thread_id, -1);
} }

View File

@@ -551,10 +551,13 @@ int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long lon
return 0; return 0;
} }
struct bool_expr_match results[n_ex_data]; if (NULL == bool_plugin_rt->matcher) {
return 0;
}
struct bool_expr_match results[n_ex_data];
n_item = ull_dedup(item_ids, n_item); n_item = ull_dedup(item_ids, n_item);
assert(bool_plugin_rt->matcher != NULL);
int n_result = bool_matcher_match(bool_plugin_rt->matcher, item_ids, n_item, results, n_ex_data); int n_result = bool_matcher_match(bool_plugin_rt->matcher, item_ids, n_item, results, n_ex_data);
for (int i = 0; i < n_result; i++) { for (int i = 0; i < n_result; i++) {
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(bool_plugin_rt->ex_data_rt, ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(bool_plugin_rt->ex_data_rt,

View File

@@ -960,9 +960,12 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
return 0; return 0;
} }
if (NULL == expr_rt->hs) {
return 0;
}
size_t n_hit_item = 0; size_t n_hit_item = 0;
struct hs_scan_result hit_results[MAX_SCANNER_HIT_ITEM_NUM]; struct hs_scan_result hit_results[MAX_SCANNER_HIT_ITEM_NUM];
int ret = adapter_hs_scan(expr_rt->hs, thread_id, data, data_len, int ret = adapter_hs_scan(expr_rt->hs, thread_id, data, data_len,
hit_results, MAX_SCANNER_HIT_ITEM_NUM, hit_results, MAX_SCANNER_HIT_ITEM_NUM,
&n_hit_item); &n_hit_item);

View File

@@ -547,8 +547,11 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
return 0; return 0;
} }
if (NULL == flag_rt->matcher) {
return 0;
}
struct flag_result hit_results[MAX_SCANNER_HIT_ITEM_NUM]; struct flag_result hit_results[MAX_SCANNER_HIT_ITEM_NUM];
int n_hit_item = flag_matcher_match(flag_rt->matcher, flag, int n_hit_item = flag_matcher_match(flag_rt->matcher, flag,
hit_results, MAX_SCANNER_HIT_ITEM_NUM); hit_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_item <= 0) { if (n_hit_item <= 0) {

View File

@@ -558,9 +558,11 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *query
return 0; return 0;
} }
struct FQDN_match results[n_ex_data]; if (NULL == fqdn_plugin_rt->engine) {
return 0;
}
assert(fqdn_plugin_rt->engine != NULL); struct FQDN_match results[n_ex_data];
int n_result = FQDN_engine_search(fqdn_plugin_rt->engine, query_fqdn, strlen(query_fqdn), int n_result = FQDN_engine_search(fqdn_plugin_rt->engine, query_fqdn, strlen(query_fqdn),
results, n_ex_data); results, n_ex_data);
for (int i = 0; i < n_result; i++) { for (int i = 0; i < n_result; i++) {

View File

@@ -548,8 +548,11 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
return 0; return 0;
} }
if (NULL == interval_rt->matcher) {
return 0;
}
struct interval_result hit_results[MAX_SCANNER_HIT_ITEM_NUM]; struct interval_result hit_results[MAX_SCANNER_HIT_ITEM_NUM];
int n_hit_item = interval_matcher_match(interval_rt->matcher, integer, int n_hit_item = interval_matcher_match(interval_rt->matcher, integer,
hit_results, MAX_SCANNER_HIT_ITEM_NUM); hit_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_item <= 0) { if (n_hit_item <= 0) {

View File

@@ -714,12 +714,11 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
return 0; return 0;
} }
struct scan_result ip_results[MAX_SCANNER_HIT_ITEM_NUM];
/* if ip_addr = "0.0.0.0" means any ip */ /* if ip_addr = "0.0.0.0" means any ip */
int any_ip_flag = 0; int any_ip_flag = 0;
struct ip_data scan_data; struct ip_data scan_data;
struct scan_result ip_results[MAX_SCANNER_HIT_ITEM_NUM];
if (ip_type == IPv4) { if (ip_type == IPv4) {
scan_data.type = IPv4; scan_data.type = IPv4;
scan_data.ipv4 = ntohl(*(uint32_t *)ip_addr); scan_data.ipv4 = ntohl(*(uint32_t *)ip_addr);
@@ -746,6 +745,11 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
if (1 == any_ip_flag) { if (1 == any_ip_flag) {
struct interval_result port_results[MAX_SCANNER_HIT_ITEM_NUM]; struct interval_result port_results[MAX_SCANNER_HIT_ITEM_NUM];
uint16_t host_port = ntohs(port); uint16_t host_port = ntohs(port);
if (NULL == ip_rt->intval_matcher) {
return 0;
}
int n_hit_port_item = interval_matcher_match(ip_rt->intval_matcher, host_port, int n_hit_port_item = interval_matcher_match(ip_rt->intval_matcher, host_port,
port_results, MAX_SCANNER_HIT_ITEM_NUM); port_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_port_item <= 0) { if (n_hit_port_item <= 0) {
@@ -776,6 +780,10 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
real_hit_item_cnt++; real_hit_item_cnt++;
} }
} else { } else {
if (NULL == ip_rt->ip_matcher) {
return 0;
}
int n_hit_ip_item = ip_matcher_match(ip_rt->ip_matcher, &scan_data, int n_hit_ip_item = ip_matcher_match(ip_rt->ip_matcher, &scan_data,
ip_results, MAX_SCANNER_HIT_ITEM_NUM); ip_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_ip_item <= 0) { if (n_hit_ip_item <= 0) {

View File

@@ -597,6 +597,10 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
return 0; return 0;
} }
if (NULL == ip_plugin_rt->ip_matcher) {
return 0;
}
struct scan_result results[n_ex_data]; struct scan_result results[n_ex_data];
struct ip_data ip_data = *(const struct ip_data *)ip_addr; struct ip_data ip_data = *(const struct ip_data *)ip_addr;
if (ip_data.type == IPv4) { if (ip_data.type == IPv4) {
@@ -605,7 +609,6 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
ipv6_ntoh(ip_data.ipv6); ipv6_ntoh(ip_data.ipv6);
} }
assert(ip_plugin_rt->ip_matcher != NULL);
int n_result = ip_matcher_match(ip_plugin_rt->ip_matcher, &ip_data, results, n_ex_data); int n_result = ip_matcher_match(ip_plugin_rt->ip_matcher, &ip_data, results, n_ex_data);
for (int i = 0; i < n_result; i++) { for (int i = 0; i < n_result; i++) {
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(ip_plugin_rt->ex_data_rt, ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(ip_plugin_rt->ex_data_rt,

View File

@@ -862,10 +862,6 @@ void* perf_fqdn_plugin_scan_thread(void *arg)
if (ret == 2) { if (ret == 2) {
hit_times++; hit_times++;
} }
for (j = 0; j < ret; j++) {
perf_fqdn_plugin_EX_free_cb(0, (void**)&(result[j]), 0, NULL);
}
} }
clock_gettime(CLOCK_MONOTONIC, &end); clock_gettime(CLOCK_MONOTONIC, &end);
@@ -1093,10 +1089,6 @@ void* perf_bool_plugin_scan_thread(void *arg)
if (ret == 1) { if (ret == 1) {
hit_times++; hit_times++;
} }
for (j = 0; j < ret; j++) {
perf_bool_plugin_ex_free_cb(0, (void**)&(result[j]), 0, NULL);
}
} }
clock_gettime(CLOCK_MONOTONIC, &end); clock_gettime(CLOCK_MONOTONIC, &end);
@@ -1286,10 +1278,6 @@ static void *ip_plugin_get_thread(void *arg)
if (ret > 0) { if (ret > 0) {
hit_times++; hit_times++;
} }
for (j = 0; j < ret; j++) {
perf_ip_plugin_EX_free_cb(table_id, (void**)&(results[j]), 0, NULL);
}
} }
clock_gettime(CLOCK_MONOTONIC, &end); clock_gettime(CLOCK_MONOTONIC, &end);