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

From: Date: Mon, 09 Nov 2026 14:08:32 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143480@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-11-09T09:05:46-05:00 Commit: https://github.com/php/php-src/commit/9099edcea132bce665df277545568f2379dce967 Raw diff: https://github.com/php/php-src/commit/9099edcea132bce665df277545568f2379dce967.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: ext/pdo_firebird: Fix DPB stack overflow on long connection parameters Changed paths: A ext/pdo_firebird/tests/dpb_overflow.phpt M NEWS M ext/pdo_firebird/firebird_driver.c Diff: diff --git a/NEWS b/NEWS index f47d51bc7d2e..68b1dcaecf3b 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,10 @@ PHP NEWS . Fixed bug GH-25253 (JIT reads parent of an unlinked class). (lazerg, mlenarciak) +- PDO_Firebird: + . Fixed stack buffer overflow with long connection user names, passwords, + charsets, or roles. (Ilia Alshanetsky) + - SOAP: . Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key). (lazerg) diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index b59171a3449c..bced4c6c6adf 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -1358,7 +1358,6 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* { "password", NULL, 0 } }; int i, ret = 0; - short buf_len = 256, dpb_len; pdo_firebird_db_handle *H = dbh->driver_data = pecalloc(1,sizeof(*H),dbh->is_persistent); @@ -1389,8 +1388,12 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* do { static char const dpb_flags[] = { isc_dpb_user_name, isc_dpb_password, isc_dpb_lc_ctype, isc_dpb_sql_role_name }; + static char const *const dpb_names[] = { "user", "password", "charset", "role" }; char const *dpb_values[] = { dbh->username, dbh->password, vars[1].optval, vars[2].optval }; char dpb_buffer[256] = { isc_dpb_version1 }, *dpb; + size_t buf_len = sizeof(dpb_buffer) - 1; + size_t dpb_value_len; + int dpb_len; if (EG(exception)) { break; @@ -1400,14 +1403,26 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* /* loop through all the provided arguments and set dpb fields accordingly */ for (i = 0; i < sizeof(dpb_flags); ++i) { - if (dpb_values[i] && buf_len > 0) { - dpb_len = slprintf(dpb, buf_len, "%c%c%s", dpb_flags[i], (unsigned char)strlen(dpb_values[i]), + if (dpb_values[i]) { + dpb_value_len = strlen(dpb_values[i]); + if (dpb_value_len + 2 >= buf_len) { + zend_throw_exception_ex(php_pdo_get_exception(), 0, + "Firebird database parameter \"%s\" is too long", dpb_names[i]); + break; + } + ZEND_ASSERT(dpb_value_len <= UCHAR_MAX); + + dpb_len = slprintf(dpb, buf_len, "%c%c%s", dpb_flags[i], (unsigned char)dpb_value_len, dpb_values[i]); dpb += dpb_len; buf_len -= dpb_len; } } + if (EG(exception)) { + break; + } + H->sql_dialect = PDO_FB_DIALECT; if (vars[3].optval) { H->sql_dialect = atoi(vars[3].optval); diff --git a/ext/pdo_firebird/tests/dpb_overflow.phpt b/ext/pdo_firebird/tests/dpb_overflow.phpt new file mode 100644 index 000000000000..27d1b3e5d15d --- /dev/null +++ b/ext/pdo_firebird/tests/dpb_overflow.phpt @@ -0,0 +1,27 @@ +--TEST-- +PDO_Firebird rejects values that overflow the database parameter buffer +--EXTENSIONS-- +pdo_firebird +--SKIPIF-- +<?php require('skipif.inc'); ?> +--FILE-- +<?php +require("testdb.inc"); + +$tests = [ + 'one-byte length overflow' => [str_repeat('u', 256), PDO_FIREBIRD_TEST_PASS], + 'DPB capacity overflow' => [str_repeat('u', 200), str_repeat('p', 52)], +]; + +foreach ($tests as $description => [$username, $password]) { + try { + new PDO(PDO_FIREBIRD_TEST_DSN, $username, $password); + echo "$description: accepted\n"; + } catch (PDOException $e) { + echo "$description: ", $e::class, ": ", $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +one-byte length overflow: PDOException: Firebird database parameter "user" is too long +DPB capacity overflow: PDOException: Firebird database parameter "password" is too long

« previous php.cvs (#143480) next »