Close #9 修复加载回调表时未正确匹配空tag的bug。6b42c711b3

This commit is contained in:
zhengchao
2019-01-24 18:55:38 +06:00
parent fb737bc36f
commit 0582e54607
4 changed files with 50 additions and 13 deletions

View File

@@ -3217,7 +3217,7 @@ void garbage_bury(MESA_lqueue_head garbage_q,int timeout,void *logger)
} }
void update_plugin_table(struct Maat_table_desc* table,const char* table_line,Maat_scanner_t* scanner, const struct rule_tag* tags, int n_tags, void* logger) void update_plugin_table(struct Maat_table_desc* table,const char* table_line,Maat_scanner_t* scanner, const struct rule_tag* tags, int n_tags, void* logger)
{ {
int i=0, ret=1; int i=0, ret=1, matched_tag=1;
unsigned int len=strlen(table_line)+1; unsigned int len=strlen(table_line)+1;
struct plugin_table_desc* plugin_desc=&(table->plugin); struct plugin_table_desc* plugin_desc=&(table->plugin);
struct Maat_table_runtime* table_rt=scanner->table_rt[table->table_id]; struct Maat_table_runtime* table_rt=scanner->table_rt[table->table_id];
@@ -3242,22 +3242,22 @@ void update_plugin_table(struct Maat_table_desc* table,const char* table_line,Ma
{ {
copy=ALLOC(char, accept_tag_len+1); copy=ALLOC(char, accept_tag_len+1);
memcpy(copy, table_line+accept_tag_offset, accept_tag_len); memcpy(copy, table_line+accept_tag_offset, accept_tag_len);
ret=compare_accept_tag(copy, tags, n_tags); matched_tag=compare_accept_tag(copy, tags, n_tags);
if(ret<0) if(matched_tag<0)
{ {
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module , MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
"update error,invalid tag format of plugin table %s:%s" "update error,invalid tag format of plugin table %s:%s"
,table->table_name[table->updating_name],table_line); ,table->table_name[table->updating_name],table_line);
table->udpate_err_cnt++; table->udpate_err_cnt++;
} }
if(ret==0) if(matched_tag==0)
{ {
table->unmatch_tag_cnt++; table->unmatch_tag_cnt++;
} }
free(copy); free(copy);
copy=NULL; copy=NULL;
} }
if(ret!=1) if(!matched_tag)
{ {
return; return;
} }

View File

@@ -762,6 +762,13 @@
"3\tFAILED\t11\t1\t{\"tag_sets\":[[{\"tag\":\"location\",\"value\":[\"北京/朝阳/华严北里\",\"上海/浦东/陆家嘴\"]},{\"tag\":\"isp\",\"value\":[\"电信\",\"联通\"]}],[{\"tag\":\"location\",\"value\":[\"北京\"]},{\"tag\":\"isp\",\"value\":[\"联通\"]}]]}\t333", "3\tFAILED\t11\t1\t{\"tag_sets\":[[{\"tag\":\"location\",\"value\":[\"北京/朝阳/华严北里\",\"上海/浦东/陆家嘴\"]},{\"tag\":\"isp\",\"value\":[\"电信\",\"联通\"]}],[{\"tag\":\"location\",\"value\":[\"北京\"]},{\"tag\":\"isp\",\"value\":[\"联通\"]}]]}\t333",
"4\tSUCCESS\t66\t1\t{}\t444" "4\tSUCCESS\t66\t1\t{}\t444"
] ]
},
{
"table_name": "IR_INTERCEPT_IP",
"table_content": [
"1000000130\t1000000130\t4\t192.168.10.99\t255.255.255.255\t0\t65535\t0.0.0.0\t255.255.255.255\t0\t65535\t0\t1\t1\t96\t1\tuser_region\t{}\t2019/1/24/18:0:34",
"161\t161\t4\t0.0.0.0\t255.255.255.255\t0\t65535\t61.135.169.121\t255.255.255.255\t0\t65535\t0\t0\t1\t96\t832\t0\t0\t2019/1/24/18:48:42"
]
} }
] ]
} }

View File

@@ -31,3 +31,4 @@
12 TEST_FOREIGN_KEY plugin {"valid":4,"foreign":[6,8],"tag":3} -- 12 TEST_FOREIGN_KEY plugin {"valid":4,"foreign":[6,8],"tag":3} --
13 COMPILE_ALIAS compile escape -- 13 COMPILE_ALIAS compile escape --
14 TEST_PLUGIN_EXDATA_TABLE plugin {"key":2,"valid":4,"tag":5,"estimate_size":1024} -- 14 TEST_PLUGIN_EXDATA_TABLE plugin {"key":2,"valid":4,"tag":5,"estimate_size":1024} --
15 IR_INTERCEPT_IP plugin {"valid":14,"tag":18}

View File

@@ -784,30 +784,59 @@ TEST(StringScan, OffsetChunk1460)
void accept_tags_entry_cb(int table_id,const char* table_line,void* u_para) void accept_tags_entry_cb(int table_id,const char* table_line,void* u_para)
{ {
int* callback_times=(int*)u_para;
char status[32]={0}; char status[32]={0};
int entry_id=-1,seq=-1; int entry_id=-1,seq=-1;
int is_valid=0; int is_valid=0;
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,status,&entry_id,&is_valid); sscanf(table_line,"%d\t%s\t%d\t%d",&seq,status,&entry_id,&is_valid);
EXPECT_STREQ(status ,"SUCCESS"); EXPECT_STREQ(status ,"SUCCESS");
(*callback_times)++;
return; return;
} }
TEST(RuleTags, Plugin) TEST(RuleTags, Plugin1)
{ {
#define RuleTags_Plugin #define RuleTags_Plugin
int table_id=0,ret=0; int ret=0;
const char* table_name="TEST_EFFECTIVE_RANGE_TABLE";
table_id=Maat_table_register(g_feather,table_name); int table_id=Maat_table_register(g_feather,"TEST_EFFECTIVE_RANGE_TABLE");
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
int callback_times=0;
ret=Maat_table_callback_register(g_feather, table_id, ret=Maat_table_callback_register(g_feather, table_id,
NULL, NULL,
accept_tags_entry_cb, accept_tags_entry_cb,
NULL, NULL,
NULL); &callback_times);
ASSERT_GE(ret, 0); ASSERT_GE(ret, 0);
EXPECT_EQ(callback_times, 3);
return;
}
void accept_tags_entry2_cb(int table_id,const char* table_line,void* u_para)
{
int* callback_times=(int*)u_para;
(*callback_times)++;
return;
}
TEST(RuleTags, Plugin2)
{
#define RuleTags_Plugin2
int ret=0;
int table_id=Maat_table_register(g_feather,"IR_INTERCEPT_IP");
ASSERT_GT(table_id, 0);
int callback_times=0;
ret=Maat_table_callback_register(g_feather, table_id,
NULL,
accept_tags_entry2_cb,
NULL,
&callback_times);
ASSERT_GE(ret, 0);
EXPECT_EQ(callback_times, 2);
return; return;
} }
@@ -1910,8 +1939,8 @@ int main(int argc, char ** argv)
const char* log_file="./test.log"; const char* log_file="./test.log";
const char* stat_file="./scan_staus.log"; const char* stat_file="./scan_staus.log";
const char* decrypt_key="mesa2017wy"; const char* decrypt_key="mesa2017wy";
const char* accept_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"}]}"; const char* accept_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}";
// const char* subsitute_acc_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"Astana\"}]}";
int scan_detail=0; int scan_detail=0;
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);