php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch 0001-mysqlnd-last_message-needs-to-respect-conn-persistent.txt for PDO MySQL Bug #77289

Patch version 2019-01-06 20:08 UTC

Return to Bug #77289 | Download this patch
Patch Revisions:

Developer: lauri.kentta@gmail.com

From e21de6e5e6ff75a9bba6cadb68b4f4187d79626b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lauri=20Kentt=C3=A4?= <lauri.kentta@gmail.com>
Date: Sun, 6 Jan 2019 22:02:34 +0200
Subject: [PATCH] mysqlnd: last_message needs to respect conn->persistent

---
 ext/mysqlnd/mysqlnd_auth.c         |  2 +-
 ext/mysqlnd/mysqlnd_commands.c     | 16 ++++++++--------
 ext/mysqlnd/mysqlnd_connection.c   |  4 ++--
 ext/mysqlnd/mysqlnd_connection.h   | 10 +++++-----
 ext/mysqlnd/mysqlnd_loaddata.c     |  3 ++-
 ext/mysqlnd/mysqlnd_result.c       |  4 ++--
 ext/mysqlnd/mysqlnd_structs.h      |  6 ++++--
 ext/mysqlnd/mysqlnd_wireprotocol.c | 10 ++++++----
 8 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c
index fa04e1b831..6288b196d1 100644
--- a/ext/mysqlnd/mysqlnd_auth.c
+++ b/ext/mysqlnd/mysqlnd_auth.c
@@ -352,7 +352,7 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
 		goto end;
 	}
 
-	SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l, auth_resp_packet.message, auth_resp_packet.message_len);
+	SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l, auth_resp_packet.message, auth_resp_packet.message_len, conn->persistent);
 	ret = PASS;
 end:
 	PACKET_FREE(&auth_resp_packet);
diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c
index 21b95a8f57..1eedbf60e8 100644
--- a/ext/mysqlnd/mysqlnd_commands.c
+++ b/ext/mysqlnd/mysqlnd_commands.c
@@ -71,7 +71,7 @@ mysqlnd_com_set_option_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_EOF_PACKET, FALSE, COM_SET_OPTION, TRUE,
-		                                   conn->error_info, conn->upsert_status, &conn->last_message);
+		                                   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 	DBG_RETURN(ret);
 }
@@ -118,7 +118,7 @@ mysqlnd_com_debug_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_EOF_PACKET, FALSE, COM_DEBUG, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 
 	DBG_RETURN(ret);
@@ -176,7 +176,7 @@ mysqlnd_com_init_db_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_INIT_DB, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 
 	/*
@@ -242,7 +242,7 @@ mysqlnd_com_ping_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, TRUE, COM_PING, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 	/*
 	  The server sends 0 but libmysql doesn't read it and has established
@@ -373,7 +373,7 @@ mysqlnd_com_process_kill_run(void *cmd)
 					   conn);
 	if (PASS == ret && read_response) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_PROCESS_KILL, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 
 	if (read_response) {
@@ -444,7 +444,7 @@ mysqlnd_com_refresh_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_REFRESH, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 
 	DBG_RETURN(ret);
@@ -504,7 +504,7 @@ mysqlnd_com_shutdown_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_SHUTDOWN, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 
 	DBG_RETURN(ret);
@@ -933,7 +933,7 @@ mysqlnd_com_stmt_reset_run(void *cmd)
 					   conn);
 	if (PASS == ret) {
 		ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_STMT_RESET, TRUE,
-										   conn->error_info, conn->upsert_status, &conn->last_message);
+										   conn->error_info, conn->upsert_status, &conn->last_message, conn->persistent);
 	}
 
 	DBG_RETURN(ret);
diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c
index a361361818..63dd13c8b0 100644
--- a/ext/mysqlnd/mysqlnd_connection.c
+++ b/ext/mysqlnd/mysqlnd_connection.c
@@ -318,7 +318,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, free_contents)(MYSQLND_CONN_DATA * conn)
 		conn->authentication_plugin_data.s = NULL;
 	}
 	if (conn->last_message.s) {
-		mnd_efree(conn->last_message.s);
+		mnd_pefree(conn->last_message.s, conn->persistent);
 		conn->last_message.s = NULL;
 	}
 
@@ -411,7 +411,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, end_psession)(MYSQLND_CONN_DATA * conn)
 		conn->current_result = NULL;
 	}
 	if (conn->last_message.s) {
-		mnd_efree(conn->last_message.s);
+		mnd_pefree(conn->last_message.s, conn->persistent);
 		conn->last_message.s = NULL;
 	}
 	conn->error_info = &conn->error_info_impl;
diff --git a/ext/mysqlnd/mysqlnd_connection.h b/ext/mysqlnd/mysqlnd_connection.h
index a5c07c3af6..a84fee915f 100644
--- a/ext/mysqlnd/mysqlnd_connection.h
+++ b/ext/mysqlnd/mysqlnd_connection.h
@@ -44,23 +44,23 @@ void mysqlnd_upsert_status_init(MYSQLND_UPSERT_STATUS * const upsert_status);
 
 
 /* Error handling */
-#define SET_NEW_MESSAGE(buf, buf_len, message, len) \
+#define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
 	{\
 		if ((buf)) { \
-			mnd_efree((buf)); \
+			mnd_pefree((buf), persistent); \
 		} \
 		if ((message)) { \
-			(buf) = mnd_pestrndup((message), (len), 0); \
+			(buf) = mnd_pestrndup((message), (len), persistent); \
 		} else { \
 			(buf) = NULL; \
 		} \
 		(buf_len) = (len); \
 	}
 
-#define SET_EMPTY_MESSAGE(buf, buf_len) \
+#define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
 	{\
 		if ((buf)) { \
-			mnd_efree((buf)); \
+			mnd_pefree((buf), persistent); \
 			(buf) = NULL; \
 		} \
 		(buf_len) = 0; \
diff --git a/ext/mysqlnd/mysqlnd_loaddata.c b/ext/mysqlnd/mysqlnd_loaddata.c
index a77961717d..33d5e2397f 100644
--- a/ext/mysqlnd/mysqlnd_loaddata.c
+++ b/ext/mysqlnd/mysqlnd_loaddata.c
@@ -216,7 +216,8 @@ infile_error:
 											PROT_OK_PACKET, FALSE, COM_QUERY, FALSE,
 											conn->error_info,
 											conn->upsert_status,
-											&conn->last_message)) {
+											&conn->last_message,
+											conn->persistent)) {
 		result = FAIL;
 	}
 
diff --git a/ext/mysqlnd/mysqlnd_result.c b/ext/mysqlnd/mysqlnd_result.c
index 38fe116686..a6e514c32e 100644
--- a/ext/mysqlnd/mysqlnd_result.c
+++ b/ext/mysqlnd/mysqlnd_result.c
@@ -440,7 +440,7 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
 				UPSERT_STATUS_SET_AFFECTED_ROWS(conn->upsert_status, rset_header.affected_rows);
 				UPSERT_STATUS_SET_LAST_INSERT_ID(conn->upsert_status, rset_header.last_insert_id);
 				SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l,
-								rset_header.info_or_local_file.s, rset_header.info_or_local_file.l);
+								rset_header.info_or_local_file.s, rset_header.info_or_local_file.l, conn->persistent);
 				/* Result set can follow UPSERT statement, check server_status */
 				if (UPSERT_STATUS_GET_SERVER_STATUS(conn->upsert_status) & SERVER_MORE_RESULTS_EXISTS) {
 					SET_CONNECTION_STATE(&conn->state, CONN_NEXT_RESULT_PENDING);
@@ -455,7 +455,7 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
 				enum_mysqlnd_collected_stats statistic = STAT_LAST;
 
 				DBG_INF("Result set pending");
-				SET_EMPTY_MESSAGE(conn->last_message.s, conn->last_message.l);
+				SET_EMPTY_MESSAGE(conn->last_message.s, conn->last_message.l, conn->persistent);
 
 				MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_RSET_QUERY);
 				UPSERT_STATUS_RESET(conn->upsert_status);
diff --git a/ext/mysqlnd/mysqlnd_structs.h b/ext/mysqlnd/mysqlnd_structs.h
index 58f9e71e6a..3ade4c688f 100644
--- a/ext/mysqlnd/mysqlnd_structs.h
+++ b/ext/mysqlnd/mysqlnd_structs.h
@@ -1007,7 +1007,8 @@ typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_c
 			MYSQLND_ERROR_INFO * const error_info,
 			MYSQLND_UPSERT_STATUS * const upsert_status,
 			const zend_bool ignore_upsert_status,  /* actually used only by LOAD DATA. COM_QUERY and COM_EXECUTE handle the responses themselves */
-			MYSQLND_STRING * const last_message);
+			MYSQLND_STRING * const last_message,
+			int persistent);
 
 typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_EOF)(
 			MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const payload_decoder_factory,
@@ -1023,7 +1024,8 @@ typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_c
 
 			MYSQLND_ERROR_INFO	* error_info,
 			MYSQLND_UPSERT_STATUS * upsert_status,
-			MYSQLND_STRING * last_message);
+			MYSQLND_STRING * last_message,
+			int persistent);
 
 
 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory)
diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c
index 1b7f4a935e..6a147fe512 100644
--- a/ext/mysqlnd/mysqlnd_wireprotocol.c
+++ b/ext/mysqlnd/mysqlnd_wireprotocol.c
@@ -2544,7 +2544,8 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_OK)(
 						MYSQLND_ERROR_INFO * const error_info,
 						MYSQLND_UPSERT_STATUS * const upsert_status,
 						const zend_bool ignore_upsert_status,  /* actually used only by LOAD DATA. COM_QUERY and COM_EXECUTE handle the responses themselves */
-						MYSQLND_STRING * const last_message)
+						MYSQLND_STRING * const last_message,
+						int persistent)
 {
 	enum_func_status ret = FAIL;
 	MYSQLND_PACKET_OK ok_response;
@@ -2574,7 +2575,7 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_OK)(
 		UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(upsert_status);
 	} else {
 		SET_NEW_MESSAGE(last_message->s, last_message->l,
-						ok_response.message, ok_response.message_len);
+						ok_response.message, ok_response.message_len, persistent);
 		if (!ignore_upsert_status) {
 			UPSERT_STATUS_RESET(upsert_status);
 			UPSERT_STATUS_SET_WARNINGS(upsert_status, ok_response.warning_count);
@@ -2643,7 +2644,8 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_response)(
 
 		MYSQLND_ERROR_INFO	* error_info,
 		MYSQLND_UPSERT_STATUS * upsert_status,
-		MYSQLND_STRING * last_message
+		MYSQLND_STRING * last_message,
+		int persistent
 	)
 {
 	enum_func_status ret = FAIL;
@@ -2653,7 +2655,7 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_response)(
 
 	switch (ok_packet) {
 		case PROT_OK_PACKET:
-			ret = payload_decoder_factory->m.send_command_handle_OK(payload_decoder_factory, error_info, upsert_status, ignore_upsert_status, last_message);
+			ret = payload_decoder_factory->m.send_command_handle_OK(payload_decoder_factory, error_info, upsert_status, ignore_upsert_status, last_message, persistent);
 			break;
 		case PROT_EOF_PACKET:
 			ret = payload_decoder_factory->m.send_command_handle_EOF(payload_decoder_factory, error_info, upsert_status);
-- 
2.20.1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 02:01:27 2024 UTC