diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp index 4d7a3f3..741afaa 100644 --- a/src/entry/Maat_api.cpp +++ b/src/entry/Maat_api.cpp @@ -114,7 +114,7 @@ static void compile_sort_para_set(struct compile_sort_para* para, const struct M } static int compile_sort_para_compare(const struct compile_sort_para* a, const struct compile_sort_para* b) { - //If both of compile rule's execute sequences are specified, compile rule with lower execute sequence is priority. + //If both of compile rule's evaluation order are specified, compile rule with small evaluation order is priority. if(a->evaluation_order!=0 && b->evaluation_order!=0) { if(a->evaluation_order - b->evaluation_order <0) @@ -126,6 +126,11 @@ static int compile_sort_para_compare(const struct compile_sort_para* a, const st return 1; } } + //If one of compile rule's evaluation order is zero, compile rule with big evaluation order is priority. + else if(a->evaluation_order + b->evaluation_order!= 0) + { + return (a->evaluation_order - b->evaluation_order >0) ? -1 : 1; + } //If compile rule's execute sequences are not specified or equal. if(a->group_cnt!=b->group_cnt) { diff --git a/test/maat_json.json b/test/maat_json.json index 1b84e7c..d772478 100644 --- a/test/maat_json.json +++ b/test/maat_json.json @@ -1397,6 +1397,33 @@ ] } ] + }, + { + "compile_id": 168, + "service": 1, + "action": 1, + "do_blacklist": 1, + "do_log": 1, + "user_region": "EvaluationOrder", + "is_valid": "yes", + "evaluation_order":"0", + "groups": [ + { + "group_name": "Untitled", + "regions": [ + { + "table_name": "HTTP_URL", + "table_type": "string", + "table_content": { + "keywords": "2019/12/27", + "expr_type": "none", + "match_method": "sub", + "format": "uncase plain" + } + } + ] + } + ] } ], "plugin_table": [ diff --git a/test/test_maatframe.cpp b/test/test_maatframe.cpp index 20d99d3..cfa0990 100644 --- a/test/test_maatframe.cpp +++ b/test/test_maatframe.cpp @@ -1417,7 +1417,7 @@ TEST(Policy, SubGroup) TEST(Policy, EvaluationOrder) { -#define TestExecuteSequence +#define EvaluationOrder int ret=0, table_id=0; size_t i=0; const char* url="cavemancircus.com/2019/12/27/pretty-girls-6/"; @@ -1431,8 +1431,10 @@ TEST(Policy, EvaluationOrder) ret=Maat_full_scan_string(g_feather, table_id, CHARSET_GBK, url, strlen(url), result+i, NULL, 4-i, &mid, 0); - EXPECT_EQ(ret, 2); + EXPECT_EQ(ret, 3); EXPECT_EQ(result[i].config_id, 166); + EXPECT_EQ(result[i+1].config_id, 167); + EXPECT_EQ(result[i+2].config_id, 168); i+=ret; struct ipaddr ipv4_addr; @@ -1458,6 +1460,7 @@ TEST(Policy, EvaluationOrder) EXPECT_EQ(result[0].config_id, 165); EXPECT_EQ(result[1].config_id, 166); EXPECT_EQ(result[2].config_id, 167); + EXPECT_EQ(result[3].config_id, 168); Maat_clean_status(&mid); }