From 42d6f9f6fd7c2dbd3d7d2a2b1780b6c504ce30a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 1 Mar 2021 14:47:45 +0000 Subject: [PATCH] Added 'ps_buffer_stmt_read_all_rows' patch for libmariadb This patch handles local variable invalidation in 'mthd_stmt_read_all_rows' due to stack swapping because of the use of 'ma_free_root' over 'stmt' buffer. --- deps/Makefile | 1 + .../ps_buffer_stmt_read_all_rows.patch | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 deps/mariadb-client-library/ps_buffer_stmt_read_all_rows.patch diff --git a/deps/Makefile b/deps/Makefile index a04010b05..5d0b671d1 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -187,6 +187,7 @@ mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a: libssl/open cd mariadb-client-library/mariadb_client && patch unittest/libmariadb/basic-t.c < ../unittest_basic-t.c.patch cd mariadb-client-library/mariadb_client && patch unittest/libmariadb/charset.c < ../unittest_charset.c.patch cd mariadb-client-library/mariadb_client && patch -p0 < ../client_deprecate_eof.patch + cd mariadb-client-library/mariadb_client && patch -p0 < ../ps_buffer_stmt_read_all_rows.patch cd mariadb-client-library/mariadb_client && CC=${CC} CXX=${CXX} ${MAKE} mariadbclient # cd mariadb-client-library/mariadb_client/include && make my_config.h diff --git a/deps/mariadb-client-library/ps_buffer_stmt_read_all_rows.patch b/deps/mariadb-client-library/ps_buffer_stmt_read_all_rows.patch new file mode 100644 index 000000000..373e4c3dd --- /dev/null +++ b/deps/mariadb-client-library/ps_buffer_stmt_read_all_rows.patch @@ -0,0 +1,29 @@ +diff --git libmariadb/mariadb_stmt.c libmariadb/mariadb_stmt.c +index bbc2831..e66d810 100644 +--- libmariadb/mariadb_stmt.c ++++ libmariadb/mariadb_stmt.c +@@ -207,6 +207,24 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) + + while ((packet_len = ma_net_safe_read(stmt->mysql, &is_data_packet)) != packet_error) + { ++ // This change is required due to the new algorithm introduced in ProxySQL in #3295. ++ // ******************************************************************************** ++ // DETAILS: ++ // Since #3295 ProxySQL performs a buffering on the resulset received by a prepared ++ // statement. This way ProxySQL doesn't require to retain the whole result of the ++ // prepared statement in memory. For this purpose it's required to free the memory ++ // allocated in 'MYSQL_STMT' via 'ma_free_root'. Because of this, local pointers ++ // within this function pointing to the result data gets invalidated due to stack ++ // swapping. Reinitializing then to the current values pointing to the new allocated ++ // memory for 'MYSQL_STMT' is required. Since this only happens when we force ++ // 'stmt->result.rows' to be '1', it's the only case in which these variables ++ // need a reset. ++ if (stmt->result.rows == 1) { ++ result= &stmt->result; ++ pprevious= &result->data->next; ++ } ++ // ******************************************************************************** ++ + p= stmt->mysql->net.read_pos; + // The check is by 'ma_net_safe_read' + if (p[0] == 0 || is_data_packet)