MXS-1346: Only parse text queries

Only text format queries (COM_QUERY, COM_STMT_PREPARE) can be parsed by
the query classifier.

Also fixed invalid use of a NULL value in a string constructor.
This commit is contained in:
Markus Mäkelä
2017-09-04 20:05:08 +03:00
parent 2ccdd93d44
commit a955e4a623
3 changed files with 31 additions and 11 deletions

View File

@ -1232,11 +1232,17 @@ static bool command_is_mandatory(const GWBUF *buffer)
static std::string get_sql(GWBUF* buffer) static std::string get_sql(GWBUF* buffer)
{ {
std::string rval;
char *sql; char *sql;
int len; int len;
modutil_extract_SQL(buffer, &sql, &len);
if (modutil_extract_SQL(buffer, &sql, &len))
{
len = MXS_MIN(len, FW_MAX_SQL_LEN); len = MXS_MIN(len, FW_MAX_SQL_LEN);
return std::string(sql, len); rval.assign(sql, len);
}
return rval;
} }
DbfwSession::DbfwSession(Dbfw* instance, MXS_SESSION* session): DbfwSession::DbfwSession(Dbfw* instance, MXS_SESSION* session):
@ -1250,9 +1256,12 @@ DbfwSession::~DbfwSession()
{ {
} }
void DbfwSession::set_error(std::string error) void DbfwSession::set_error(const char* error)
{ {
if (error)
{
m_error = error; m_error = error;
}
} }
std::string DbfwSession::get_error()const std::string DbfwSession::get_error()const

View File

@ -174,7 +174,7 @@ public:
DbfwSession(Dbfw* instance, MXS_SESSION* session); DbfwSession(Dbfw* instance, MXS_SESSION* session);
~DbfwSession(); ~DbfwSession();
void set_error(std::string error); void set_error(const char* error);
std::string get_error() const; std::string get_error() const;
void clear_error(); void clear_error();
int send_error(); int send_error();

View File

@ -48,12 +48,23 @@ bool Rule::matches_query(DbfwSession* session, GWBUF* buffer, char** msg) const
bool Rule::matches_query_type(GWBUF* buffer) const bool Rule::matches_query_type(GWBUF* buffer) const
{ {
bool rval = true;
if (on_queries != FW_OP_UNDEFINED)
{
rval = false;
if (query_is_sql(buffer))
{
qc_query_op_t optype = qc_get_operation(buffer); qc_query_op_t optype = qc_get_operation(buffer);
return on_queries == FW_OP_UNDEFINED || rval = (on_queries & qc_op_to_fw_op(optype)) ||
(on_queries & qc_op_to_fw_op(optype)) ||
(MYSQL_IS_COM_INIT_DB(GWBUF_DATA(buffer)) && (MYSQL_IS_COM_INIT_DB(GWBUF_DATA(buffer)) &&
(on_queries & FW_OP_CHANGE_DB)); (on_queries & FW_OP_CHANGE_DB));
}
}
return rval;
} }
const std::string& Rule::name() const const std::string& Rule::name() const