MXS-2470 Validate GWBUFs
A GWBUF given to any gwbuf-function: - Must not be NULL. Exceptions are gwbuf_free() and gwbuf_append(), in analogy with free() and realloc() respectively. - Must be the head of a chain. - Must be owned by the calling thread.
This commit is contained in:
@ -556,6 +556,8 @@ static size_t get_complete_packets_length(GWBUF* buffer)
|
||||
size_t offset = 0;
|
||||
size_t total = 0;
|
||||
|
||||
GWBUF* tail = buffer ? buffer->tail : nullptr;
|
||||
|
||||
while (buffer && gwbuf_copy_data(buffer, offset, 3, packet_len) == 3)
|
||||
{
|
||||
uint32_t len = gw_mysql_get_byte3(packet_len) + MYSQL_HEADER_LEN;
|
||||
@ -579,6 +581,13 @@ static size_t get_complete_packets_length(GWBUF* buffer)
|
||||
buflen = buffer ? GWBUF_LENGTH(buffer) : 0;
|
||||
}
|
||||
|
||||
// TODO: Fix GWBUF interface so that this function can be written without
|
||||
// TODO: knowledge about the internals of GWBUF.
|
||||
if (buffer)
|
||||
{
|
||||
buffer->tail = tail;
|
||||
}
|
||||
|
||||
/** Either the buffer ended with a complete packet or the buffer
|
||||
* contains more data than is required. */
|
||||
if (read_len == 0 || (buffer && read_len < buflen))
|
||||
|
||||
Reference in New Issue
Block a user