From 3afc89ae800d5e8cea246f3eeafe7a09c912de35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 10 Oct 2017 07:25:47 +0300 Subject: [PATCH] Fix debug assertion in modutil_count_signal_packets The original offset needs to be separately tracked to assert that an OK packet is not the first packet in the buffer. The functional offset into the buffer is modified to reduce the need to iterate over buffers that have already been processed. --- server/core/modutil.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/core/modutil.cc b/server/core/modutil.cc index 06316f599..a5850ac6b 100644 --- a/server/core/modutil.cc +++ b/server/core/modutil.cc @@ -631,6 +631,7 @@ GWBUF* modutil_get_complete_packets(GWBUF **p_readbuf) int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more_dest, modutil_state* state) { unsigned int len = gwbuf_length(reply); + ss_debug(int real_offset = 0); int eof = 0; int err = 0; size_t offset = 0; @@ -669,7 +670,8 @@ int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more_dest, mod else if (more && command == MYSQL_REPLY_OK) { // This should not be the first packet - ss_dassert(pktlen >= MYSQL_OK_PACKET_MIN_LEN && offset > 0); + ss_dassert(pktlen >= MYSQL_OK_PACKET_MIN_LEN); + ss_dassert(real_offset > 0); uint8_t data[payloadlen - 1]; gwbuf_copy_data(reply, offset + MYSQL_HEADER_LEN + 1, sizeof(data), data); @@ -691,6 +693,8 @@ int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more_dest, mod } offset += pktlen; + ss_debug(real_offset += pktlen); + if (offset >= GWBUF_LENGTH(reply) && reply->next) { offset -= GWBUF_LENGTH(reply);