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

From: Date: Tue, 29 Sep 2026 18:04:39 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141713@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-09-29T14:01:29-04:00 Commit: https://github.com/php/php-src/commit/9dcdf3cd8d8dafc60d8bdc751193200ca188addf Raw diff: https://github.com/php/php-src/commit/9dcdf3cd8d8dafc60d8bdc751193200ca188addf.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: Fix GH-23741: pdo_dblib use-after-free of statement error state Changed paths: A ext/pdo_dblib/tests/gh23741.phpt A ext/pdo_dblib/tests/gh23741_2.phpt M NEWS M ext/pdo_dblib/dblib_driver.c M ext/pdo_dblib/dblib_stmt.c Diff: diff --git a/NEWS b/NEWS index d700a7be0de0..18d07cc32fff 100644 --- a/NEWS +++ b/NEWS @@ -54,6 +54,12 @@ PHP NEWS . Fixed PDOStatement::bindParam() and bindColumn() leaking the driver options value. (Ilia Alshanetsky) +- PDO_DBLIB: + . Fixed bug GH-23741 (segfault after a failed query inside a PDO + transaction). Errors raised by beginTransaction(), commit(), rollBack() + and lastInsertId() are now reported instead of being dropped. + (Ilia Alshanetsky) + - PDO_PGSQL: . Fixed crash when a persistent connection fails. (KentarouTakeda) diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 7189954ec412..68055e192e62 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -75,11 +75,12 @@ static void dblib_handle_closer(pdo_dbh_t *dbh) pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; if (H) { - pdo_dblib_err_dtor(&H->err); if (H->link) { + dbsetuserdata(H->link, (BYTE*) &H->err); dbclose(H->link); H->link = NULL; } + pdo_dblib_err_dtor(&H->err); if (H->login) { dbfreelogin(H->login); H->login = NULL; @@ -200,6 +201,8 @@ static bool pdo_dblib_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; + dbsetuserdata(H->link, (BYTE*) &H->err); + if (FAIL == dbcmd(H->link, cmd)) { return false; } @@ -238,6 +241,8 @@ zend_string *dblib_handle_last_id(pdo_dbh_t *dbh, const zend_string *name) * Would use scope_identity() but it's not implemented on Sybase */ + dbsetuserdata(H->link, (BYTE*) &H->err); + if (FAIL == dbcmd(H->link, "SELECT @@IDENTITY")) { return NULL; } diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c index 0b97b1dfb076..e244a39fc32c 100644 --- a/ext/pdo_dblib/dblib_stmt.c +++ b/ext/pdo_dblib/dblib_stmt.c @@ -93,6 +93,8 @@ static int pdo_dblib_stmt_cursor_closer(pdo_stmt_t *stmt) pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data; pdo_dblib_db_handle *H = S->H; + dbsetuserdata(H->link, (BYTE*) &S->err); + /* Cancel any pending results */ dbcancel(H->link); @@ -150,6 +152,8 @@ static int pdo_dblib_stmt_next_rowset(pdo_stmt_t *stmt) pdo_dblib_db_handle *H = S->H; RETCODE ret = SUCCESS; + dbsetuserdata(H->link, (BYTE*) &S->err); + /* Ideally use dbcanquery here, but there is a bug in FreeTDS's implementation of dbcanquery * It has been resolved but is currently only available in nightly builds */ @@ -199,6 +203,8 @@ static int pdo_dblib_stmt_fetch(pdo_stmt_t *stmt, pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data; pdo_dblib_db_handle *H = S->H; + dbsetuserdata(H->link, (BYTE*) &S->err); + ret = dbnextrow(H->link); if (FAIL == ret) { @@ -224,6 +230,8 @@ static int pdo_dblib_stmt_describe(pdo_stmt_t *stmt, int colno) return FAILURE; } + dbsetuserdata(H->link, (BYTE*) &S->err); + if (colno == 0) { S->computed_column_name_count = 0; } @@ -348,6 +356,8 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *zv, enum pd DBCHAR *tmp_data; DBINT data_len, tmp_data_len; + dbsetuserdata(H->link, (BYTE*) &S->err); + coltype = dbcoltype(H->link, colno+1); data = dbdata(H->link, colno+1); data_len = dbdatlen(H->link, colno+1); @@ -470,7 +480,7 @@ static int pdo_dblib_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zva return FAILURE; } - array_init(return_value); + dbsetuserdata(H->link, (BYTE*) &S->err); dbtypeinfo = dbcoltypeinfo(H->link, colno+1); @@ -478,6 +488,8 @@ static int pdo_dblib_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zva coltype = dbcoltype(H->link, colno+1); + array_init(return_value); + add_assoc_long(return_value, "max_length", dbcollen(H->link, colno+1) ); add_assoc_long(return_value, "precision", (int) dbtypeinfo->precision ); add_assoc_long(return_value, "scale", (int) dbtypeinfo->scale ); diff --git a/ext/pdo_dblib/tests/gh23741.phpt b/ext/pdo_dblib/tests/gh23741.phpt new file mode 100644 index 000000000000..f3fc1a5ce445 --- /dev/null +++ b/ext/pdo_dblib/tests/gh23741.phpt @@ -0,0 +1,38 @@ +--TEST-- +GH-23741 (pdo_dblib: segfault after a failed query inside a PDO transaction) +--EXTENSIONS-- +pdo_dblib +--SKIPIF-- +<?php +require __DIR__ . '/config.inc'; +getDbConnection(); +?> +--FILE-- +<?php +require __DIR__ . '/config.inc'; + +$db = getDbConnection(PDO::class, [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]); + +$db->query('CREATE TABLE gh23741 (id int)'); + +$db->beginTransaction(); +echo 'failing query inside the transaction: '; +var_dump($db->query('CREATE VIEW gh23741 AS SELECT 1 AS x')); +$db->rollBack(); + +echo 'query after the failure: '; +var_dump($db->query('DROP TABLE IF EXISTS gh23741') instanceof PDOStatement); + +echo "survived connection teardown\n"; +?> +--CLEAN-- +<?php +require __DIR__ . '/config.inc'; +$db = getDbConnection(); +$db->exec('DROP VIEW IF EXISTS gh23741'); +$db->exec('DROP TABLE IF EXISTS gh23741'); +?> +--EXPECT-- +failing query inside the transaction: bool(false) +query after the failure: bool(true) +survived connection teardown diff --git a/ext/pdo_dblib/tests/gh23741_2.phpt b/ext/pdo_dblib/tests/gh23741_2.phpt new file mode 100644 index 000000000000..d8297c3671ea --- /dev/null +++ b/ext/pdo_dblib/tests/gh23741_2.phpt @@ -0,0 +1,27 @@ +--TEST-- +GH-23741 (pdo_dblib: crash reading metadata after a sibling statement is freed) +--EXTENSIONS-- +pdo_dblib +--SKIPIF-- +<?php +require __DIR__ . '/config.inc'; +getDbConnection(); +?> +--FILE-- +<?php +require __DIR__ . '/config.inc'; + +$db = getDbConnection(PDO::class, [PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]); + +$wide = $db->query('SELECT 1 AS a, 2 AS b, 3 AS c'); +$narrow = $db->query('SELECT 9 AS z'); +unset($narrow); + +echo 'metadata for a column the connection no longer has: '; +var_dump($wide->getColumnMeta(2)); + +echo "survived the out-of-range column\n"; +?> +--EXPECT-- +metadata for a column the connection no longer has: bool(false) +survived the out-of-range column

« previous php.cvs (#141713) next »