Skip to content

Commit 5f7ef2c

Browse files
committed
Fix GH-16990 "dba_list() is now zero-indexed instead of using resource ids"
1 parent ba7dee5 commit 5f7ef2c

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP NEWS
1919
- Curl:
2020
. Fix various memory leaks in curl mime handling. (nielsdos)
2121

22+
- DBA:
23+
. Fixed bug GH-16990 (dba_list() is now zero-indexed instead of using
24+
resource ids) (kocsismate)
25+
2226
- DOM:
2327
. Fixed bug GH-16906 (Reloading document can cause UAF in iterator).
2428
(nielsdos)

ext/dba/dba.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,9 +1293,9 @@ PHP_FUNCTION(dba_list)
12931293

12941294
zval *zv;
12951295
ZEND_HASH_MAP_FOREACH_VAL(&DBA_G(connections), zv) {
1296-
dba_info *info = Z_DBA_INFO_P(zv);
1297-
if (info) {
1298-
add_next_index_str(return_value, zend_string_copy(info->path));
1296+
dba_connection *connection = Z_DBA_CONNECTION_P(zv);
1297+
if (connection->info) {
1298+
add_index_str(return_value, connection->std.handle, zend_string_copy(connection->info->path));
12991299
}
13001300
} ZEND_HASH_FOREACH_END();
13011301
}

ext/dba/tests/gh16990.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
GH-16990 (dba_list() is now zero-indexed instead of using resource ids)
3+
--EXTENSIONS--
4+
dba
5+
--CONFLICTS--
6+
dba
7+
--SKIPIF--
8+
<?php
9+
$handler = "flatfile";
10+
require_once(__DIR__ .'/skipif.inc');
11+
?>
12+
--FILE--
13+
<?php
14+
15+
require_once(__DIR__ .'/test.inc');
16+
17+
$db_filename1 = __DIR__.'/test1.dbm';
18+
$db1 = dba_open($db_filename1, 'r', 'flatfile');
19+
if (!$db1) {
20+
var_dump("Database file creation failed");
21+
}
22+
23+
$db_filename2 = __DIR__.'/test2.dbm';
24+
$db2 = dba_open($db_filename2, 'r', 'flatfile');
25+
if (!$db2) {
26+
var_dump("Database file creation failed");
27+
}
28+
29+
var_dump(dba_list());
30+
?>
31+
--CLEAN--
32+
<?php
33+
@unlink(__DIR__.'/test1.dbm');
34+
@unlink(__DIR__.'/test2.dbm');
35+
?>
36+
--EXPECTF--
37+
array(2) {
38+
[1] =>
39+
string(%d) "%s/test1.dbm"
40+
[2] =>
41+
string(%d) "%s/test2.dbm"
42+
}

0 commit comments

Comments
 (0)