From 0b77c3f05fea647e057c6441957bda4b6d05c45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Mar 2019 12:58:02 +0200 Subject: [PATCH] MXS-2324: Prevent stack overflow with large results If a result consists of only OK packets, they would be processed recursively which most of the time leads to a stack overflow. This can be prevented by consuming all OK packets in the result in one go. --- server/modules/protocol/MySQL/rwbackend.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/modules/protocol/MySQL/rwbackend.cc b/server/modules/protocol/MySQL/rwbackend.cc index e2161d10d..5924d60b0 100644 --- a/server/modules/protocol/MySQL/rwbackend.cc +++ b/server/modules/protocol/MySQL/rwbackend.cc @@ -192,6 +192,14 @@ void RWBackend::process_reply(GWBUF* buffer) // TODO: Don't clone the buffer GWBUF* tmp = gwbuf_clone(buffer); tmp = gwbuf_consume(tmp, mxs_mysql_get_packet_len(tmp)); + + // Consume repeating OK packets + while (mxs_mysql_more_results_after_ok(buffer) && have_next_packet(tmp)) + { + tmp = gwbuf_consume(tmp, mxs_mysql_get_packet_len(tmp)); + mxb_assert(tmp); + } + process_reply(tmp); gwbuf_free(tmp); return;