Masking: Handle NULL values properly
This commit is contained in:
@ -191,12 +191,6 @@ void MaskingFilterSession::handle_row(GWBUF* pPacket)
|
||||
m_state = EXPECTING_NOTHING;
|
||||
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:
|
||||
{
|
||||
ComQueryResponse::Row row(response);
|
||||
@ -210,7 +204,10 @@ void MaskingFilterSession::handle_row(GWBUF* pPacket)
|
||||
{
|
||||
LEncString s = *i;
|
||||
|
||||
if (!s.is_null())
|
||||
{
|
||||
pRule->rewrite(s);
|
||||
}
|
||||
|
||||
MXS_NOTICE("String: %s", (*i).to_string().c_str());
|
||||
}
|
||||
|
||||
@ -212,9 +212,18 @@ public:
|
||||
* @param pData Pointer to the beginning of a length encoded string
|
||||
*/
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pString = NULL;
|
||||
m_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -224,9 +233,19 @@ public:
|
||||
* one past the end of the length encoded string.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pString = NULL;
|
||||
m_length = 0;
|
||||
++(*ppData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator to the beginning of the string.
|
||||
@ -300,9 +319,16 @@ public:
|
||||
* @return An @c std::string
|
||||
*/
|
||||
std::string to_string() const
|
||||
{
|
||||
if (m_pString)
|
||||
{
|
||||
return std::string(m_pString, m_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::string("NULL");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the string to a @c ostream.
|
||||
@ -317,6 +343,16 @@ public:
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is NULL
|
||||
*
|
||||
* @return True, if the string represents a NULL value.
|
||||
*/
|
||||
bool is_null() const
|
||||
{
|
||||
return m_pString == NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
char* m_pString; /*<! Pointer to beginning of string, NOT zero-terminated. */
|
||||
size_t m_length; /*<! Length of string. */
|
||||
|
||||
Reference in New Issue
Block a user