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

From: Date: Mon, 09 Nov 2026 14:08:35 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143482@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-11-09T09:05:47-05:00 Commit: https://github.com/php/php-src/commit/60d880ddae5ad1957855790b29b60c3c2a241b18 Raw diff: https://github.com/php/php-src/commit/60d880ddae5ad1957855790b29b60c3c2a241b18.diff Merge branch 'PHP-8.6' * PHP-8.6: ext/pdo_firebird: Fix DPB stack overflow on long connection parameters Changed paths: A ext/pdo_firebird/tests/dpb_overflow.phpt M ext/pdo_firebird/firebird_driver.c Diff: diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index 36f380b2122b..233a087f9e41 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -1355,7 +1355,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); @@ -1386,8 +1385,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; @@ -1397,14 +1400,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 (#143482) next »