fb6fb6
From 58006537fc5f133ae8549efe5118cde418b3ace9 Mon Sep 17 00:00:00 2001
fb6fb6
From: Stanislav Malyshev <smalyshev@gmail.com>
fb6fb6
Date: Mon, 6 Jun 2022 00:56:51 -0600
fb6fb6
Subject: [PATCH] Fix bug #81719: mysqlnd/pdo password buffer overflow
fb6fb6
fb6fb6
---
fb6fb6
 ext/mysqlnd/mysqlnd_wireprotocol.c | 3 ++-
fb6fb6
 1 file changed, 2 insertions(+), 1 deletion(-)
fb6fb6
fb6fb6
diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c
fb6fb6
index 87b2e7c31331..e4a298adaea4 100644
fb6fb6
--- a/ext/mysqlnd/mysqlnd_wireprotocol.c
fb6fb6
+++ b/ext/mysqlnd/mysqlnd_wireprotocol.c
fb6fb6
@@ -771,7 +771,8 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet)
fb6fb6
 	MYSQLND_VIO * vio = conn->vio;
fb6fb6
 	MYSQLND_STATS * stats = conn->stats;
fb6fb6
 	MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
fb6fb6
-	zend_uchar * const buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
fb6fb6
+	size_t total_packet_size = packet->auth_data_len + MYSQLND_HEADER_SIZE;
fb6fb6
+	zend_uchar * const buffer = pfc->cmd_buffer.length >= total_packet_size? pfc->cmd_buffer.buffer : mnd_emalloc(total_packet_size);
fb6fb6
 	zend_uchar * p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */
fb6fb6
 
fb6fb6
 	DBG_ENTER("php_mysqlnd_change_auth_response_write");