add boundary check
This commit is contained in:
@@ -583,6 +583,10 @@ next:
|
|||||||
|
|
||||||
struct adapter_hs_stream *adapter_hs_stream_open(struct adapter_hs *hs_instance, int thread_id)
|
struct adapter_hs_stream *adapter_hs_stream_open(struct adapter_hs *hs_instance, int thread_id)
|
||||||
{
|
{
|
||||||
|
if (NULL == hs_instance || thread_id < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct adapter_hs_stream *hs_stream = ALLOC(struct adapter_hs_stream, 1);
|
struct adapter_hs_stream *hs_stream = ALLOC(struct adapter_hs_stream, 1);
|
||||||
hs_error_t err;
|
hs_error_t err;
|
||||||
|
|
||||||
@@ -617,6 +621,11 @@ int adapter_hs_scan_stream(struct adapter_hs_stream *hs_stream, const char *data
|
|||||||
{
|
{
|
||||||
hs_error_t err;
|
hs_error_t err;
|
||||||
|
|
||||||
|
if (NULL == hs_stream || NULL == data || 0 == data_len ||
|
||||||
|
NULL == results || 0 == n_result || NULL == n_hit_result) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int thread_id = hs_stream->thread_id;
|
int thread_id = hs_stream->thread_id;
|
||||||
if (hs_stream->literal_stream != NULL) {
|
if (hs_stream->literal_stream != NULL) {
|
||||||
err = hs_scan_stream(hs_stream->literal_stream, data, data_len,
|
err = hs_scan_stream(hs_stream->literal_stream, data, data_len,
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ int expr_runtime_commit(void *expr_runtime, const char *table_name);
|
|||||||
* @retval the num of hit group_id
|
* @retval the num of hit group_id
|
||||||
*/
|
*/
|
||||||
int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *data,
|
int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *data,
|
||||||
size_t data_len, int vtable_ids, struct maat_state *state);
|
size_t data_len, int vtable_id, struct maat_state *state);
|
||||||
|
|
||||||
void expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id);
|
int expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id);
|
||||||
int expr_runtime_stream_scan(struct expr_runtime *expr_rt, const char *data, size_t data_len,
|
int expr_runtime_stream_scan(struct expr_runtime *expr_rt, const char *data, size_t data_len,
|
||||||
int vtable_id, struct maat_state *state);
|
int vtable_id, struct maat_state *state);
|
||||||
void expr_runtime_stream_close(struct expr_runtime *expr_rt);
|
void expr_runtime_stream_close(struct expr_runtime *expr_rt);
|
||||||
|
|||||||
@@ -1531,11 +1531,12 @@ struct maat_stream *maat_scan_stream_open(struct maat *maat_instance, int table_
|
|||||||
|
|
||||||
void *expr_rt = table_manager_get_runtime(stream->ref_maat_instance->tbl_mgr,
|
void *expr_rt = table_manager_get_runtime(stream->ref_maat_instance->tbl_mgr,
|
||||||
stream->physical_table_ids[i]);
|
stream->physical_table_ids[i]);
|
||||||
if (NULL == expr_rt) {
|
assert(expr_rt != NULL);
|
||||||
|
|
||||||
|
int ret = expr_runtime_stream_open((struct expr_runtime *)expr_rt, thread_id);
|
||||||
|
if (ret < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_runtime_stream_open((struct expr_runtime *)expr_rt, thread_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
|||||||
@@ -222,11 +222,7 @@ int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rcu_hash_add(ex_data_rt->htable, key, key_len, ex_container);
|
rcu_hash_add(ex_data_rt->htable, key, key_len, ex_container);
|
||||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
|
||||||
key, key_len);
|
|
||||||
log_info(ex_data_rt->logger, MODULE_EX_DATA,
|
|
||||||
"ex_data_runtime_add_ex_container rcu_hash_add ex_data_rt->htable:%p key:%p key_len:%zu, ex_container:%p tmp_container:%p",
|
|
||||||
ex_data_rt->htable, key, key_len, ex_container, tmp_container);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -847,8 +847,13 @@ int expr_runtime_commit(void *expr_runtime, const char *table_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *data,
|
int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *data,
|
||||||
size_t data_len, int vtable_ids, struct maat_state *state)
|
size_t data_len, int vtable_id, struct maat_state *state)
|
||||||
{
|
{
|
||||||
|
if (NULL == expr_rt || thread_id < 0 || NULL == data || 0 == data_len
|
||||||
|
|| vtable_id < 0 || NULL == state) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
size_t n_hit_item = 0;
|
size_t n_hit_item = 0;
|
||||||
struct hs_scan_result hit_results[MAX_SCANNER_HIT_ITEM_NUM] = {0};
|
struct hs_scan_result hit_results[MAX_SCANNER_HIT_ITEM_NUM] = {0};
|
||||||
|
|
||||||
@@ -885,7 +890,7 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *d
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t group_hit_cnt = 0;
|
size_t group_hit_cnt = 0;
|
||||||
ret = maat_compile_state_update(expr_rt->item_hash, vtable_ids, hit_item_ids,
|
ret = maat_compile_state_update(expr_rt->item_hash, vtable_id, hit_item_ids,
|
||||||
real_hit_item_cnt, &group_hit_cnt, state);
|
real_hit_item_cnt, &group_hit_cnt, state);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -894,20 +899,27 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *d
|
|||||||
return group_hit_cnt;
|
return group_hit_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id)
|
int expr_runtime_stream_open(struct expr_runtime *expr_rt, int thread_id)
|
||||||
{
|
{
|
||||||
if (NULL == expr_rt) {
|
if (NULL == expr_rt || thread_id < 0) {
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct adapter_hs_stream *hs_stream = adapter_hs_stream_open(expr_rt->hs, thread_id);
|
struct adapter_hs_stream *hs_stream = adapter_hs_stream_open(expr_rt->hs, thread_id);
|
||||||
|
if (NULL == hs_stream) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
expr_rt->hs_stream = hs_stream;
|
expr_rt->hs_stream = hs_stream;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int expr_runtime_stream_scan(struct expr_runtime *expr_rt, const char *data, size_t data_len,
|
int expr_runtime_stream_scan(struct expr_runtime *expr_rt, const char *data, size_t data_len,
|
||||||
int vtable_id, struct maat_state *state)
|
int vtable_id, struct maat_state *state)
|
||||||
{
|
{
|
||||||
if (NULL == expr_rt) {
|
if (NULL == expr_rt || NULL == data || 0 == data_len ||
|
||||||
|
vtable_id < 0 || NULL == state) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -261,7 +261,33 @@ TEST_F(MaatStringScan, ExprAndExprPlus) {
|
|||||||
EXPECT_EQ(results[0], 195);
|
EXPECT_EQ(results[0], 195);
|
||||||
maat_state_free(&state);
|
maat_state_free(&state);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
TEST_F(MaatStringScan, StreamInput) {
|
||||||
|
long long results[ARRAY_SIZE] = {0};
|
||||||
|
size_t n_hit_result = 0;
|
||||||
|
struct maat_state *state = NULL;
|
||||||
|
const char *scan_data = "http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567";
|
||||||
|
const char *table_name = "HTTP_URL_STREAM";
|
||||||
|
|
||||||
|
int table_id = maat_table_get_id(g_maat_instance, table_name);
|
||||||
|
ASSERT_GT(table_id, 0);
|
||||||
|
|
||||||
|
struct maat_stream *sp = maat_scan_stream_open(g_maat_instance, table_id, 0);
|
||||||
|
ASSERT_FALSE(sp==NULL);
|
||||||
|
|
||||||
|
int ret = maat_scan_stream(&sp, "www.cyberessays.com", strlen("www.cyberessays.com"),
|
||||||
|
results, ARRAY_SIZE, &n_hit_result, &state);
|
||||||
|
EXPECT_EQ(ret, MAAT_SCAN_OK);
|
||||||
|
|
||||||
|
ret = maat_scan_stream(&sp, scan_data, strlen(scan_data), results, ARRAY_SIZE,
|
||||||
|
&n_hit_result, &state);
|
||||||
|
maat_scan_stream_close(&sp);
|
||||||
|
|
||||||
|
EXPECT_EQ(ret, MAAT_SCAN_HIT);
|
||||||
|
EXPECT_EQ(results[0], 125);
|
||||||
|
maat_state_free(&state);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
//TODO:
|
//TODO:
|
||||||
#if 0
|
#if 0
|
||||||
TEST_F(MaatStringScan, ShouldNotHitExprPlus) {
|
TEST_F(MaatStringScan, ShouldNotHitExprPlus) {
|
||||||
@@ -1565,7 +1591,7 @@ int main(int argc, char ** argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *accept_tags = "{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}";
|
const char* accept_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}";
|
||||||
char redis_ip[64] = "127.0.0.1";
|
char redis_ip[64] = "127.0.0.1";
|
||||||
int redis_port = 6379;
|
int redis_port = 6379;
|
||||||
int redis_db = 0;
|
int redis_db = 0;
|
||||||
|
|||||||
@@ -271,7 +271,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"compile_id": 126,
|
"compile_id": 126,
|
||||||
"service": 1,
|
"service": 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user