From ba289dc5892475dcca372c92858cbb4ffa9dbd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 2 Jul 2020 14:32:51 +0300 Subject: [PATCH] Fix debug assertion in cache The call to gwbuf_length will fail if the pointed to buffer isn't the head of the chain. To prevent this, the length is calculated before the buffer is appended. Also fixed the use of gwbuf_append. The return value should be assigned and the code shouldn't reply on the value passed to the function being correct. --- server/modules/filter/cache/cachefiltersession.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/modules/filter/cache/cachefiltersession.cc b/server/modules/filter/cache/cachefiltersession.cc index 659a01919..4676db095 100644 --- a/server/modules/filter/cache/cachefiltersession.cc +++ b/server/modules/filter/cache/cachefiltersession.cc @@ -358,10 +358,11 @@ int CacheFilterSession::clientReply(GWBUF* pData) if (m_res.pData) { - gwbuf_append(m_res.pData, pData); + auto len = gwbuf_length(pData); // pData may be a chain, so not GWBUF_LENGTH(). + m_res.pData = gwbuf_append(m_res.pData, pData); m_res.pData_last = pData; m_res.offset_last = m_res.length; - m_res.length += gwbuf_length(pData); // pData may be a chain, so not GWBUF_LENGTH(). + m_res.length += len; } else {