summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuwentan <[email protected]>2023-06-20 17:34:46 +0800
committerliuwentan <[email protected]>2023-06-20 17:34:46 +0800
commit7cb24d96f8e3e00c6d5d0e2fc5016d7dbb140da1 (patch)
tree5298bc94653dddbce2409ae4bb84dfe05c464900
parent8ad355d5d71f75635a9e05e645153406496504af (diff)
[PATCH]handle matcher NULL pointerv4.0.27
-rw-r--r--src/maat_api.c14
-rw-r--r--src/maat_bool_plugin.c7
-rw-r--r--src/maat_expr.c5
-rw-r--r--src/maat_flag.c5
-rw-r--r--src/maat_fqdn_plugin.c6
-rw-r--r--src/maat_interval.c5
-rw-r--r--src/maat_ip.c14
-rw-r--r--src/maat_ip_plugin.c5
-rw-r--r--test/maat_framework_perf_gtest.cpp12
9 files changed, 48 insertions, 25 deletions
diff --git a/src/maat_api.c b/src/maat_api.c
index 4c35c0a..c0304bc 100644
--- a/src/maat_api.c
+++ b/src/maat_api.c
@@ -428,13 +428,23 @@ int maat_get_table_id(struct maat *maat_inst, const char *table_name)
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);
}
-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);
}
diff --git a/src/maat_bool_plugin.c b/src/maat_bool_plugin.c
index e4574b9..4478591 100644
--- a/src/maat_bool_plugin.c
+++ b/src/maat_bool_plugin.c
@@ -551,10 +551,13 @@ int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long lon
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);
- assert(bool_plugin_rt->matcher != NULL);
+
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++) {
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(bool_plugin_rt->ex_data_rt,
diff --git a/src/maat_expr.c b/src/maat_expr.c
index b80587d..e5a7c8f 100644
--- a/src/maat_expr.c
+++ b/src/maat_expr.c
@@ -960,9 +960,12 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
return 0;
}
+ if (NULL == expr_rt->hs) {
+ return 0;
+ }
+
size_t n_hit_item = 0;
struct hs_scan_result hit_results[MAX_SCANNER_HIT_ITEM_NUM];
-
int ret = adapter_hs_scan(expr_rt->hs, thread_id, data, data_len,
hit_results, MAX_SCANNER_HIT_ITEM_NUM,
&n_hit_item);
diff --git a/src/maat_flag.c b/src/maat_flag.c
index 0c03ef1..e645d0a 100644
--- a/src/maat_flag.c
+++ b/src/maat_flag.c
@@ -547,8 +547,11 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
return 0;
}
+ if (NULL == flag_rt->matcher) {
+ return 0;
+ }
+
struct flag_result hit_results[MAX_SCANNER_HIT_ITEM_NUM];
-
int n_hit_item = flag_matcher_match(flag_rt->matcher, flag,
hit_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_item <= 0) {
diff --git a/src/maat_fqdn_plugin.c b/src/maat_fqdn_plugin.c
index 265090e..560841e 100644
--- a/src/maat_fqdn_plugin.c
+++ b/src/maat_fqdn_plugin.c
@@ -558,9 +558,11 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *query
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),
results, n_ex_data);
for (int i = 0; i < n_result; i++) {
diff --git a/src/maat_interval.c b/src/maat_interval.c
index 57e4f3c..c738ef4 100644
--- a/src/maat_interval.c
+++ b/src/maat_interval.c
@@ -548,8 +548,11 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
return 0;
}
+ if (NULL == interval_rt->matcher) {
+ return 0;
+ }
+
struct interval_result hit_results[MAX_SCANNER_HIT_ITEM_NUM];
-
int n_hit_item = interval_matcher_match(interval_rt->matcher, integer,
hit_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_item <= 0) {
diff --git a/src/maat_ip.c b/src/maat_ip.c
index 62d4d2a..73e650d 100644
--- a/src/maat_ip.c
+++ b/src/maat_ip.c
@@ -714,12 +714,11 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
return 0;
}
- struct scan_result ip_results[MAX_SCANNER_HIT_ITEM_NUM];
-
/* if ip_addr = "0.0.0.0" means any ip */
int any_ip_flag = 0;
-
struct ip_data scan_data;
+ struct scan_result ip_results[MAX_SCANNER_HIT_ITEM_NUM];
+
if (ip_type == IPv4) {
scan_data.type = IPv4;
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) {
struct interval_result port_results[MAX_SCANNER_HIT_ITEM_NUM];
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,
port_results, MAX_SCANNER_HIT_ITEM_NUM);
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++;
}
} else {
+ if (NULL == ip_rt->ip_matcher) {
+ return 0;
+ }
+
int n_hit_ip_item = ip_matcher_match(ip_rt->ip_matcher, &scan_data,
ip_results, MAX_SCANNER_HIT_ITEM_NUM);
if (n_hit_ip_item <= 0) {
diff --git a/src/maat_ip_plugin.c b/src/maat_ip_plugin.c
index 321ebac..864ea35 100644
--- a/src/maat_ip_plugin.c
+++ b/src/maat_ip_plugin.c
@@ -597,6 +597,10 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
return 0;
}
+ if (NULL == ip_plugin_rt->ip_matcher) {
+ return 0;
+ }
+
struct scan_result results[n_ex_data];
struct ip_data ip_data = *(const struct ip_data *)ip_addr;
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);
}
- assert(ip_plugin_rt->ip_matcher != NULL);
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++) {
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(ip_plugin_rt->ex_data_rt,
diff --git a/test/maat_framework_perf_gtest.cpp b/test/maat_framework_perf_gtest.cpp
index 34a2ebd..db92e5e 100644
--- a/test/maat_framework_perf_gtest.cpp
+++ b/test/maat_framework_perf_gtest.cpp
@@ -862,10 +862,6 @@ void* perf_fqdn_plugin_scan_thread(void *arg)
if (ret == 2) {
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);
@@ -1093,10 +1089,6 @@ void* perf_bool_plugin_scan_thread(void *arg)
if (ret == 1) {
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);
@@ -1286,10 +1278,6 @@ static void *ip_plugin_get_thread(void *arg)
if (ret > 0) {
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);