[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Sun, 22 Nov 2026 15:54:49 +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-144030@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-11-22T10:45:16-05:00 Commit: https://github.com/php/php-src/commit/9107cd69e85c64e8f01505cb9a8fa6b37faa7fa1 Raw diff: https://github.com/php/php-src/commit/9107cd69e85c64e8f01505cb9a8fa6b37faa7fa1.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: ext/pdo_sqlite: Fix use-after-free of bound string and LOB parameters Changed paths: A ext/pdo_sqlite/tests/gh25588.phpt M NEWS M ext/pdo_sqlite/sqlite_statement.c Diff: diff --git a/NEWS b/NEWS index de0f20f614dc..ec03fd9682f6 100644 --- a/NEWS +++ b/NEWS @@ -150,6 +150,10 @@ PHP NEWS . Fixed a crash when executing a prepared statement again after a failed execute() with libmysqlclient. (Ilia Alshanetsky) +- PDO_SQLite: + . Fixed bug GH-25588 (Use-after-free of a string parameter omitted on a later + execute() or rebound while fetching). (Ilia Alshanetsky) + - POSIX: . Fixed bug GH-25530 (posix_get_last_error() returns an error from a previous request). (Artem Ukrainskiy) diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c index 0d088c99ce7a..a9b5b9531e22 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

« previous php.cvs (#144030) next »