Skip to content

Commit b50dc1e

Browse files
authored
Fix DBA on MacOS (#7611)
The name zend_string* must be copied instead of returned directly in case the group part of the array is empty.
1 parent e56c506 commit b50dc1e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

ext/dba/dba.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ static zend_string* php_dba_make_key(HashTable *key)
108108
// TODO: Use zval_try_get_string() or try_convert_to_string() instead?
109109
convert_to_string(group);
110110
convert_to_string(name);
111+
// TODO: Check ZSTR_LEN(name) != 0
111112
if (Z_STRLEN_P(group) == 0) {
112-
return Z_STR_P(name);
113+
return zend_string_copy(Z_STR_P(name));
113114
}
114115
return zend_strpprintf(0, "[%s]%s", Z_STRVAL_P(group), Z_STRVAL_P(name));
115116
}

ext/dba/tests/dba_array_keys.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
DBA check behaviour of array keys
3+
--EXTENSIONS--
4+
dba
5+
--SKIPIF--
6+
<?php
7+
require_once(__DIR__ .'/skipif.inc');
8+
die("info $HND handler used");
9+
?>
10+
--FILE--
11+
<?php
12+
require_once(__DIR__ .'/test.inc');
13+
$db_file = dba_open($db_file, "n", $handler);
14+
15+
if ($db_file === false) {
16+
die('Error creating database');
17+
}
18+
19+
var_dump(dba_insert(['group', 'name'], 'Normal group', $db_file));
20+
var_dump(dba_insert(['group', ''], 'Empty name', $db_file));
21+
var_dump(dba_insert(['', 'name'], 'Empty group', $db_file));
22+
var_dump(dba_insert(['', ''], 'Empty keys', $db_file));
23+
var_dump(dba_fetch(['group', 'name'], $db_file));
24+
var_dump(dba_fetch(['group', ''], $db_file));
25+
var_dump(dba_fetch(['', 'name'], $db_file));
26+
var_dump(dba_fetch(['', ''], $db_file));
27+
dba_close($db_file);
28+
29+
?>
30+
--CLEAN--
31+
<?php
32+
require(__DIR__ .'/clean.inc');
33+
?>
34+
--EXPECT--
35+
bool(true)
36+
bool(true)
37+
bool(true)
38+
bool(true)
39+
string(12) "Normal group"
40+
string(10) "Empty name"
41+
string(11) "Empty group"
42+
string(10) "Empty keys"

0 commit comments

Comments
 (0)