From 50264b03a073e8ab3157cda288dd3b8322346381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 3 Dec 2024 00:46:28 +0100 Subject: [PATCH] Fix GH-16990 "dba_list() is now zero-indexed instead of using resource ids" closes GH-17005 --- NEWS | 4 ++++ ext/dba/dba.c | 6 ++--- ext/dba/tests/gh16990.phpt | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 ext/dba/tests/gh16990.phpt diff --git a/NEWS b/NEWS index e572109d267..bd6e28a0c7a 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,10 @@ PHP NEWS - Curl: . Fix various memory leaks in curl mime handling. (nielsdos) +- DBA: + . Fixed bug GH-16990 (dba_list() is now zero-indexed instead of using + resource ids) (kocsismate) + - DOM: . Fixed bug GH-16906 (Reloading document can cause UAF in iterator). (nielsdos) diff --git a/ext/dba/dba.c b/ext/dba/dba.c index f094fb1f612..e4986e1cd23 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -1293,9 +1293,9 @@ PHP_FUNCTION(dba_list) zval *zv; ZEND_HASH_MAP_FOREACH_VAL(&DBA_G(connections), zv) { - dba_info *info = Z_DBA_INFO_P(zv); - if (info) { - add_next_index_str(return_value, zend_string_copy(info->path)); + dba_connection *connection = Z_DBA_CONNECTION_P(zv); + if (connection->info) { + add_index_str(return_value, connection->std.handle, zend_string_copy(connection->info->path)); } } ZEND_HASH_FOREACH_END(); } diff --git a/ext/dba/tests/gh16990.phpt b/ext/dba/tests/gh16990.phpt new file mode 100644 index 00000000000..f3191904722 --- /dev/null +++ b/ext/dba/tests/gh16990.phpt @@ -0,0 +1,46 @@ +--TEST-- +GH-16990 (dba_list() is now zero-indexed instead of using resource ids) +--EXTENSIONS-- +dba +--CONFLICTS-- +dba +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +array(2) { + [2]=> + string(%d) "%s%etest1.dbm" + [4]=> + string(%d) "%s%etest2.dbm" +}