Created
September 15, 2021 20:08
-
-
Save adsr/8376550b43205e03b6f6803ff5f79e37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/include/query_processor.h b/include/query_processor.h | |
| index 0fe43edb..4a7cf65d 100644 | |
| --- a/include/query_processor.h | |
| +++ b/include/query_processor.h | |
| @@ -104,6 +104,7 @@ struct _Query_Processor_rule_t { | |
| char *comment; // #643 | |
| void *regex_engine1; | |
| void *regex_engine2; | |
| + void *regex_engine3; | |
| uint64_t hits; | |
| struct _Query_Processor_rule_t *parent; // pointer to parent, to speed up parent update | |
| }; | |
| diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp | |
| index 4d8eee46..8212b116 100644 | |
| --- a/lib/Query_Processor.cpp | |
| +++ b/lib/Query_Processor.cpp | |
| @@ -308,7 +308,7 @@ static unsigned long long mem_used_rule(QP_rule_t *qr) { | |
| if (qr->username) | |
| s+=strlen(qr->username); | |
| if (qr->schemaname) | |
| - s+=strlen(qr->schemaname); | |
| + s+=strlen(qr->schemaname)*10; // not sure how much is used for regex | |
| if (qr->client_addr) | |
| s+=strlen(qr->client_addr); | |
| if (qr->proxy_addr) | |
| @@ -325,7 +325,7 @@ static unsigned long long mem_used_rule(QP_rule_t *qr) { | |
| s+=strlen(qr->OK_msg); | |
| if (qr->comment) | |
| s+=strlen(qr->comment); | |
| - if (qr->match_digest || qr->match_pattern || qr->replace_pattern) { | |
| + if (qr->match_digest || qr->match_pattern || qr->replace_pattern || qr->schemaname) { | |
| s+= sizeof(__RE2_objects_t *)+sizeof(__RE2_objects_t); | |
| s+= sizeof(pcrecpp::RE_Options *) + sizeof(pcrecpp::RE_Options); | |
| s+= sizeof(pcrecpp::RE *) + sizeof(pcrecpp::RE); | |
| @@ -350,6 +350,8 @@ static re2_t * compile_query_rule(QP_rule_t *qr, int i) { | |
| r->re2=new RE2(qr->match_digest, *r->opt2); | |
| } else if (i==2) { | |
| r->re2=new RE2(qr->match_pattern, *r->opt2); | |
| + } else if (i==3) { | |
| + r->re2=new RE2(qr->schemaname, *r->opt2); | |
| } | |
| } else { | |
| r->opt1=new pcrecpp::RE_Options(); | |
| @@ -360,6 +362,8 @@ static re2_t * compile_query_rule(QP_rule_t *qr, int i) { | |
| r->re1=new pcrecpp::RE(qr->match_digest, *r->opt1); | |
| } else if (i==2) { | |
| r->re1=new pcrecpp::RE(qr->match_pattern, *r->opt1); | |
| + } else if (i==3) { | |
| + r->re1=new pcrecpp::RE(qr->schemaname, *r->opt1); | |
| } | |
| } | |
| return r; | |
| @@ -395,6 +399,14 @@ static void __delete_query_rule(QP_rule_t *qr) { | |
| if (r->re2) { delete r->re2; r->re2=NULL; } | |
| free(qr->regex_engine2); | |
| } | |
| + if (qr->regex_engine3) { | |
| + re2_t *r=(re2_t *)qr->regex_engine3; | |
| + if (r->opt1) { delete r->opt1; r->opt1=NULL; } | |
| + if (r->re1) { delete r->re1; r->re1=NULL; } | |
| + if (r->opt2) { delete r->opt2; r->opt2=NULL; } | |
| + if (r->re2) { delete r->re2; r->re2=NULL; } | |
| + free(qr->regex_engine3); | |
| + } | |
| free(qr); | |
| }; | |
| @@ -644,6 +656,7 @@ QP_rule_t * Query_Processor::new_query_rule(int rule_id, bool active, char *user | |
| newQR->comment=(comment ? strdup(comment) : NULL); // see issue #643 | |
| newQR->regex_engine1=NULL; | |
| newQR->regex_engine2=NULL; | |
| + newQR->regex_engine3=NULL; | |
| newQR->hits=0; | |
| newQR->client_addr_wildcard_position = -1; // not existing by default | |
| @@ -1356,6 +1369,10 @@ Query_Processor_Output * Query_Processor::process_mysql_query(MySQL_Session *ses | |
| proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Compiling regex for rule_id: %d, match_pattern: \n", qr2->rule_id, qr2->match_pattern); | |
| qr2->regex_engine2=(void *)compile_query_rule(qr2,2); | |
| } | |
| + if (qr2->schemaname) { | |
| + proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Compiling regex for rule_id: %d, schemaname: \n", qr2->rule_id, qr2->schemaname); | |
| + qr2->regex_engine3=(void *)compile_query_rule(qr2,3); | |
| + } | |
| _thr_SQP_rules->push_back(qr2); | |
| } | |
| } | |
| @@ -1419,7 +1436,14 @@ __internal_loop: | |
| } | |
| } | |
| if (qr->schemaname && strlen(qr->schemaname)) { | |
| - if (strcmp(qr->schemaname,sess->client_myds->myconn->userinfo->schemaname)!=0) { | |
| + re2p = (re2_t *)qr->regex_engine3; | |
| + bool rc; | |
| + if (re2p->re2) { | |
| + rc=RE2::PartialMatch(sess->client_myds->myconn->userinfo->schemaname,*re2p->re2); | |
| + } else { | |
| + rc=re2p->re1->PartialMatch(sess->client_myds->myconn->userinfo->schemaname); | |
| + } | |
| + if ((rc==true && qr->negate_match_pattern==true) || (rc==false && qr->negate_match_pattern==false)) { | |
| proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "query rule %d has no matching schemaname\n", qr->rule_id); | |
| continue; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment