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;
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;
pRule->rewrite(s);
if (!s.is_null())
{
pRule->rewrite(s);
}
MXS_NOTICE("String: %s", (*i).to_string().c_str());
}

View File

@ -213,7 +213,16 @@ public:
*/
LEncString(uint8_t* pData)
{
m_pString = mxs_lestr_consume(&pData, &m_length);
// 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;
}
}
/**
@ -225,7 +234,17 @@ public:
*/
LEncString(uint8_t** ppData)
{
m_pString = mxs_lestr_consume(ppData, &m_length);
// 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);
}
}
/**
@ -301,7 +320,14 @@ public:
*/
std::string to_string() const
{
return std::string(m_pString, m_length);
if (m_pString)
{
return std::string(m_pString, m_length);
}
else
{
return std::string("NULL");
}
}
/**
@ -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. */