Masking: Handle NULL values properly

This commit is contained in:
Johan Wikman
2017-01-02 15:42:25 +02:00
parent 8127454f24
commit e7981c9d67
2 changed files with 43 additions and 10 deletions

View File

@ -191,12 +191,6 @@ void MaskingFilterSession::handle_row(GWBUF* pPacket)
m_state = EXPECTING_NOTHING; m_state = EXPECTING_NOTHING;
break; break;
case 0xfb: // NULL is sent as 0xfb
MXS_NOTICE("NULL");
// We must ask for the rule so as not to get out of sync.
m_res.get_rule();
break;
default: default:
{ {
ComQueryResponse::Row row(response); ComQueryResponse::Row row(response);
@ -210,7 +204,10 @@ void MaskingFilterSession::handle_row(GWBUF* pPacket)
{ {
LEncString s = *i; LEncString s = *i;
if (!s.is_null())
{
pRule->rewrite(s); pRule->rewrite(s);
}
MXS_NOTICE("String: %s", (*i).to_string().c_str()); MXS_NOTICE("String: %s", (*i).to_string().c_str());
} }

View File

@ -212,9 +212,18 @@ public:
* @param pData Pointer to the beginning of a length encoded string * @param pData Pointer to the beginning of a length encoded string
*/ */
LEncString(uint8_t* pData) LEncString(uint8_t* pData)
{
// NULL is sent as 0xfb. See https://dev.mysql.com/doc/internals/en/com-query-response.html
if (*pData != 0xfb)
{ {
m_pString = mxs_lestr_consume(&pData, &m_length); m_pString = mxs_lestr_consume(&pData, &m_length);
} }
else
{
m_pString = NULL;
m_length = 0;
}
}
/** /**
* Constructor * Constructor
@ -224,9 +233,19 @@ public:
* one past the end of the length encoded string. * one past the end of the length encoded string.
*/ */
LEncString(uint8_t** ppData) LEncString(uint8_t** ppData)
{
// NULL is sent as 0xfb. See https://dev.mysql.com/doc/internals/en/com-query-response.html
if (**ppData != 0xfb)
{ {
m_pString = mxs_lestr_consume(ppData, &m_length); m_pString = mxs_lestr_consume(ppData, &m_length);
} }
else
{
m_pString = NULL;
m_length = 0;
++(*ppData);
}
}
/** /**
* Returns an iterator to the beginning of the string. * Returns an iterator to the beginning of the string.
@ -300,9 +319,16 @@ public:
* @return An @c std::string * @return An @c std::string
*/ */
std::string to_string() const std::string to_string() const
{
if (m_pString)
{ {
return std::string(m_pString, m_length); return std::string(m_pString, m_length);
} }
else
{
return std::string("NULL");
}
}
/** /**
* Print the string to a @c ostream. * Print the string to a @c ostream.
@ -317,6 +343,16 @@ public:
return o; return o;
} }
/**
* Is NULL
*
* @return True, if the string represents a NULL value.
*/
bool is_null() const
{
return m_pString == NULL;
}
private: private:
char* m_pString; /*<! Pointer to beginning of string, NOT zero-terminated. */ char* m_pString; /*<! Pointer to beginning of string, NOT zero-terminated. */
size_t m_length; /*<! Length of string. */ size_t m_length; /*<! Length of string. */