[php-src] master: Merge branch 'PHP-8.6'
| From: | Ilia Alshanetsky | Date: | Sun, 22 Nov 2026 15:54:56 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144032@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-11-22T10:47:48-05:00
Commit: https://github.com/php/php-src/commit/7e7e5933e12821dd714191d881ba112b91834752
Raw diff: https://github.com/php/php-src/commit/7e7e5933e12821dd714191d881ba112b91834752.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
ext/pdo_sqlite: Fix use-after-free of bound string and LOB parameters
Changed paths:
A ext/pdo_sqlite/tests/gh25588.phpt
M ext/pdo_sqlite/sqlite_statement.c
Diff:
diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c
index ef81ef38bb10..12d98000ae93 100644
--- a/ext/pdo_sqlite/sqlite_statement.c
+++ b/ext/pdo_sqlite/sqlite_statement.c
@@ -162,9 +162,10 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct
pdo_bound_param_d
if (SQLITE_OK == sqlite3_bind_blob(S->stmt, param->paramno + 1,
Z_STRVAL_P(parameter),
Z_STRLEN_P(parameter),
- SQLITE_STATIC)) {
+ SQLITE_TRANSIENT)) {
return 1;
}
+ pdo_sqlite_error_stmt(stmt);
return 0;
case PDO_PARAM_STR:
@@ -185,7 +186,7 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
if (SQLITE_OK == sqlite3_bind_text(S->stmt, param->paramno + 1,
Z_STRVAL_P(parameter),
Z_STRLEN_P(parameter),
- SQLITE_STATIC)) {
+ SQLITE_TRANSIENT)) {
return 1;
}
}
diff --git a/ext/pdo_sqlite/tests/gh25588.phpt b/ext/pdo_sqlite/tests/gh25588.phpt
new file mode 100644
index 000000000000..b5bbe925f567
--- /dev/null
+++ b/ext/pdo_sqlite/tests/gh25588.phpt
@@ -0,0 +1,101 @@
+--TEST--
+GH-25588 (Use-after-free of a bound string after its PDO parameter is released)
+--EXTENSIONS--
+pdo_sqlite
+--FILE--
+<?php
+$db = new PDO('sqlite::memory:');
+$db->exec('CREATE TABLE t (a TEXT, b TEXT)');
+$db->exec("INSERT INTO t VALUES ('xxxxxxxxxx', NULL), ('xxxxxxxxxx',
NULL), ('xxxxxxxxxx', NULL)");
+
+$stmt = $db->prepare('INSERT INTO t VALUES (:a, :b)');
+$stmt->execute([':a' => str_repeat('a', 10), ':b' =>
str_repeat('b', 10)]);
+$stmt->execute([':a' => 1234567890]);
+echo "execute() with fewer params:\n";
+var_dump($db->query('SELECT a, b FROM t WHERE b IS NOT NULL ORDER BY
rowid')->fetchAll(PDO::FETCH_NUM));
+
+$stmt = $db->prepare('SELECT rowid FROM t WHERE a = :a ORDER BY rowid');
+$stmt->bindValue(':a', str_repeat('x', 10));
+$stmt->execute();
+echo "bindValue() during fetch:\n";
+var_dump($stmt->fetchColumn());
+$stmt->bindValue(':a', str_repeat('q', 10));
+$reuse = str_repeat('w', 10);
+while (($id = $stmt->fetchColumn()) !== false) {
+ var_dump($id);
+}
+
+$value = str_repeat('x', 10);
+$stmt = $db->prepare('SELECT rowid FROM t WHERE a = :a ORDER BY rowid');
+$stmt->bindParam(':a', $value);
+$stmt->execute();
+echo "bindParam() variable reassigned during fetch:\n";
+var_dump($stmt->fetchColumn());
+$value = str_repeat('q', 10);
+$reuse = str_repeat('w', 10);
+while (($id = $stmt->fetchColumn()) !== false) {
+ var_dump($id);
+}
+
+$stmt = $db->prepare('INSERT INTO t VALUES (:a, :b)');
+$stmt->bindValue(':a', str_repeat('c', 10));
+$stmt->bindValue(':b', str_repeat('d', 10), PDO::PARAM_LOB);
+$stmt->execute();
+$stmt->execute([':a' => 1234567891]);
+echo "PARAM_LOB omitted on execute():\n";
+var_dump($db->query("SELECT a, b FROM t WHERE a IN ('cccccccccc',
'1234567891') ORDER BY rowid")->fetchAll(PDO::FETCH_NUM));
+
+echo "PARAM_LOB bind failure:\n";
+$stmt = $db->prepare('SELECT :a');
+$stmt->bindValue(':nope', 'x', PDO::PARAM_LOB);
+try {
+ $stmt->execute();
+} catch (PDOException $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+?>
+--EXPECT--
+execute() with fewer params:
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(10) "aaaaaaaaaa"
+ [1]=>
+ string(10) "bbbbbbbbbb"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(10) "1234567890"
+ [1]=>
+ string(10) "bbbbbbbbbb"
+ }
+}
+bindValue() during fetch:
+int(1)
+int(2)
+int(3)
+bindParam() variable reassigned during fetch:
+int(1)
+int(2)
+int(3)
+PARAM_LOB omitted on execute():
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(10) "cccccccccc"
+ [1]=>
+ string(10) "dddddddddd"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(10) "1234567891"
+ [1]=>
+ string(10) "dddddddddd"
+ }
+}
+PARAM_LOB bind failure:
+PDOException: SQLSTATE[HY000]: General error: 25 column index out of range