[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Ilia Alshanetsky | Date: | Fri, 30 Oct 2026 00:16:41 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142971@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-10-29T20:16:04-04:00
Commit: https://github.com/php/php-src/commit/e2d40b5b1b1c4260c327fede68b54a990859050a
Raw diff: https://github.com/php/php-src/commit/e2d40b5b1b1c4260c327fede68b54a990859050a.diff
Merge branch 'PHP-8.5' into PHP-8.6
Changed paths:
A ext/odbc/tests/gh25036.phpt
M NEWS
M ext/odbc/php_odbc.c
Diff:
diff --git a/NEWS b/NEWS
index faab0b180e40..e1e63f21b0ad 100644
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,10 @@ PHP NEWS
. Fixed bug GH-24609 (OK packets without an info message rejected on x32
builds). (lazerg)
+- ODBC:
+ . Fixed bug GH-25036 (odbc_prepare() corrupts the heap when the driver
+ cannot describe a parameter). (Ilia Alshanetsky)
+
- Opcache:
. Fixed tracing JIT returning a wrapped integer instead of a float on
integer overflow after an integer was compared with a float or
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index 642307935c77..e10d60d64cb3 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -952,6 +952,7 @@ PHP_FUNCTION(odbc_prepare)
}
result->conn_ptr = conn;
result->fetched = 0;
+ odbc_insert_new_result(conn, return_value);
result->param_info = (odbc_param_info *) safe_emalloc(sizeof(odbc_param_info),
result->numparams, 0);
for (i=0;i<result->numparams;i++) {
@@ -959,14 +960,11 @@ PHP_FUNCTION(odbc_prepare)
&result->param_info[i].scale, &result->param_info[i].nullable);
if (rc == SQL_ERROR) {
odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter");
- SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
- efree(result->param_info);
+ odbc_result_free(result);
zval_ptr_dtor(return_value);
RETURN_FALSE;
}
}
-
- odbc_insert_new_result(conn, return_value);
}
/* }}} */
diff --git a/ext/odbc/tests/gh25036.phpt b/ext/odbc/tests/gh25036.phpt
new file mode 100644
index 000000000000..16b3226361cb
--- /dev/null
+++ b/ext/odbc/tests/gh25036.phpt
@@ -0,0 +1,39 @@
+--TEST--
+GH-25036 (odbc_prepare() double free when SQLDescribeParam() fails)
+--EXTENSIONS--
+odbc
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+
+include 'config.inc';
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+$live = odbc_exec($conn, 'SELECT 1 AS a');
+
+var_dump(odbc_prepare($conn, 'SELECT ? FROM gh25036_missing'));
+var_dump(odbc_prepare($conn, 'SELECT ?, ? FROM gh25036_missing'));
+
+var_dump(odbc_fetch_array($live));
+
+odbc_close($conn);
+
+try {
+ odbc_fetch_row($live);
+} catch (Error $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+?>
+--EXPECTF--
+Warning: odbc_prepare(): SQL error: %s, SQL state %s in SQLDescribeParameter in %s on line %d
+bool(false)
+
+Warning: odbc_prepare(): SQL error: %s, SQL state %s in SQLDescribeParameter in %s on line %d
+bool(false)
+array(1) {
+ ["a"]=>
+ string(1) "1"
+}
+Error: ODBC result has already been closed