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.
pull/3326/head
Javier Jaramago Fernández 5 years ago
parent 6d49f5fa27
commit 42d6f9f6fd

1
deps/Makefile vendored

@ -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

@ -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)
Loading…
Cancel
Save