[php-src] PHP-8.4: Fix GH-24640: Reject "#" in tcadb paths (#24656)

From: Date: Sun, 22 Nov 2026 09:12:57 +0000
Subject: [php-src] PHP-8.4: Fix GH-24640: Reject "#" in tcadb paths (#24656)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144017@lists.php.net to get a copy of this message
Author: lazerg (lazerg) Committer: Weilin Du (LamentXU123) Date: 2026-11-22T16:19:16+08:00 Commit: https://github.com/php/php-src/commit/e66232191f9271acbd47ef93651e04a1fb7df5dd Raw diff: https://github.com/php/php-src/commit/e66232191f9271acbd47ef93651e04a1fb7df5dd.diff Fix GH-24640: Reject "#" in tcadb paths (#24656) Tokyo Cabinet treats text after "#" as tuning parameters. That means tcadb could open a different file from the one PHP uses for locking. Reject paths containing "#" before initializing the tcadb handle, because Tokyo Cabinet provides no way to escape the character. Closes #24656 Changed paths: A ext/dba/tests/gh24640.phpt M NEWS M ext/dba/dba_tcadb.c Diff: diff --git a/NEWS b/NEWS index f8f4bd9e6331..f90e69fa164f 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,8 @@ PHP NEWS - DBA: . Fixed dba_close() not closing a database opened with dba_popen(). (Ilia Alshanetsky) + . Fixed bug GH-24640 (tcadb handler allows injecting Tokyo Cabinet + parameters via "#" in the path). (Lazizbek Ergashev) - DOM: . Fixed bug GH-25268 (NULL php_libxml_ref_obj dereference in diff --git a/ext/dba/dba_tcadb.c b/ext/dba/dba_tcadb.c index 6f4cb01e69e5..201fc73a2ad2 100644 --- a/ext/dba/dba_tcadb.c +++ b/ext/dba/dba_tcadb.c @@ -34,7 +34,14 @@ typedef struct { DBA_OPEN_FUNC(tcadb) { char *path_string; - TCADB *tcadb = tcadbnew(); + TCADB *tcadb; + + if (memchr(ZSTR_VAL(info->path), '#', ZSTR_LEN(info->path))) { + *error = "Path must not contain \"#\""; + return FAILURE; + } + + tcadb = tcadbnew(); if (tcadb) { switch(info->mode) { diff --git a/ext/dba/tests/gh24640.phpt b/ext/dba/tests/gh24640.phpt new file mode 100644 index 000000000000..6a7fce3d0c9c --- /dev/null +++ b/ext/dba/tests/gh24640.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-24640 (tcadb handler allows injecting Tokyo Cabinet parameters via "#" in the path) +--EXTENSIONS-- +dba +--SKIPIF-- +<?php +require_once __DIR__ . '/setup/setup_dba_tests.inc'; +check_skip('tcadb'); +?> +--FILE-- +<?php +$db_file = __DIR__ . '/gh24640.tch'; + +var_dump(dba_open($db_file . '#bnum=1000', 'n-', 'tcadb')); +var_dump(file_exists($db_file)); +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/gh24640.tch'); +?> +--EXPECTF-- +Warning: dba_open(): Driver initialization failed for handler: tcadb: Path must not contain "#" in %s on line %d +bool(false) +bool(false)

« previous php.cvs (#144017) next »