Skip to content

Commit 50264b0

Browse files
committed
Fix phpGH-16990 "dba_list() is now zero-indexed instead of using resource ids"
closes phpGH-17005
1 parent 6753c55 commit 50264b0

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

NEWS

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

23+
- DBA:
24+
. Fixed bug GH-16990 (dba_list() is now zero-indexed instead of using
25+
resource ids) (kocsismate)
26+
2327
- DOM:
2428
. Fixed bug GH-16906 (Reloading document can cause UAF in iterator).
2529
(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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
require_once __DIR__ . '/setup/setup_dba_tests.inc';
10+
check_skip('flatfile');
11+
?>
12+
--FILE--
13+
<?php
14+
15+
require_once(__DIR__ .'/test.inc');
16+
17+
$foo1 = new stdClass();
18+
19+
$db_filename1 = __DIR__.'/test1.dbm';
20+
$db1 = dba_open($db_filename1, 'c', 'flatfile');
21+
if (!$db1) {
22+
var_dump("Database file creation failed");
23+
}
24+
25+
$foo2 = new stdClass();
26+
27+
$db_filename2 = __DIR__.'/test2.dbm';
28+
$db2 = dba_open($db_filename2, 'c', 'flatfile');
29+
if (!$db2) {
30+
var_dump("Database file creation failed");
31+
}
32+
33+
var_dump(dba_list());
34+
?>
35+
--CLEAN--
36+
<?php
37+
@unlink(__DIR__.'/test1.dbm');
38+
@unlink(__DIR__.'/test2.dbm');
39+
?>
40+
--EXPECTF--
41+
array(2) {
42+
[2]=>
43+
string(%d) "%s%etest1.dbm"
44+
[4]=>
45+
string(%d) "%s%etest2.dbm"
46+
}

0 commit comments

Comments
 (0)