Skip to content

Commit b1211c1

Browse files
cmb69kamil-tekiela
andcommitted
Fix GH-15432: Heap corruption when querying a vector
Since the mysqlnd result set is arena allocated, we must not simply free it, but rather call the appropriate `free_result` method. Co-authored-by: Kamil Tekiela <[email protected]>
1 parent 836e6fa commit b1211c1

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.24
44

5+
- MySQLnd:
6+
. Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb,
7+
Kamil Tekiela)
8+
59
29 Aug 2024, PHP 8.2.23
610

711
- Core:

ext/mysqli/tests/gh15432.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug GH-15432 (Heap corruption when querying a vector)
3+
--EXTENSIONS--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require 'connect.inc';
8+
$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
9+
if ($link === false) {
10+
die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
11+
}
12+
if ($link->server_version < 90000 || $link->server_version >= 10_00_00) {
13+
die("skip MySQL 9.0.0+ needed");
14+
}
15+
?>
16+
--FILE--
17+
<?php
18+
require 'connect.inc';
19+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
20+
var_dump($link->query('SELECT STRING_TO_VECTOR("[1.05, -17.8, 32]")'));
21+
?>
22+
--EXPECTF--
23+
Warning: mysqli::query(): Unknown type 242 sent by the server. Please send a report to the developers in %s on line %d
24+
bool(false)

ext/mysqlnd/mysqlnd_result.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
302302
if (FAIL == (ret = result->m.read_result_metadata(result, conn))) {
303303
/* For PS, we leave them in Prepared state */
304304
if (!stmt && conn->current_result) {
305-
mnd_efree(conn->current_result);
305+
conn->current_result->m.free_result(conn->current_result, TRUE);
306306
conn->current_result = NULL;
307307
}
308308
DBG_ERR("Error occurred while reading metadata");

0 commit comments

Comments
 (0)