Fix CDC error detection
The error detection assumed the buffer was null-terminated which was never guaranteed.
This commit is contained in:
parent
02a65f311a
commit
01e1c616ba
@ -523,14 +523,14 @@ bool Connection::do_registration()
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool Connection::is_error(const char* str)
|
||||
bool Connection::is_error()
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
if (str[0] == 'E' && str[1] == 'R' && str[2] == 'R')
|
||||
if (m_buffer.size() >= 3 && m_buffer[0] == 'E' && m_buffer[1] == 'R' && m_buffer[2] == 'R')
|
||||
{
|
||||
m_error = "MaxScale responded with an error: ";
|
||||
m_error += str;
|
||||
m_error.append(m_buffer.begin(), m_buffer.end());
|
||||
rval = true;
|
||||
}
|
||||
|
||||
@ -545,6 +545,12 @@ bool Connection::read_row(std::string& dest)
|
||||
{
|
||||
if (!m_buffer.empty())
|
||||
{
|
||||
if (is_error())
|
||||
{
|
||||
rval = false;
|
||||
break;
|
||||
}
|
||||
|
||||
std::deque<char>::iterator it = std::find(m_buffer.begin(), m_buffer.end(), '\n');
|
||||
|
||||
if (it != m_buffer.end())
|
||||
@ -577,18 +583,13 @@ bool Connection::read_row(std::string& dest)
|
||||
assert(std::find(m_buffer.begin(), m_buffer.end(), '\n') == m_buffer.end());
|
||||
std::copy(buf, buf + rc, std::back_inserter(m_buffer));
|
||||
|
||||
if (is_error(&m_buffer[0]))
|
||||
if (is_error())
|
||||
{
|
||||
rval = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_error(dest.c_str()))
|
||||
{
|
||||
rval = false;
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ private:
|
||||
bool read_row(std::string& dest);
|
||||
void process_schema(json_t* json);
|
||||
SRow process_row(json_t*);
|
||||
bool is_error(const char* str);
|
||||
bool is_error();
|
||||
|
||||
// Lower-level functions
|
||||
int wait_for_event(short events);
|
||||
|
Loading…
x
Reference in New Issue
Block a user