Skip to content

Commit cf1664e

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-9155: dba_open("non-existing", "c-", "flatfile") segfaults
2 parents 7d36703 + a442e29 commit cf1664e

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414

1515
- DBA:
1616
. Fixed LMDB driver memory leak on DB creation failure (Girgias)
17+
. Fixed bug GH-9155 (dba_open("non-existing", "c-", "flatfile") segfaults)
18+
(cmb)
1719

1820
- MBString:
1921
. Fixed bug GH-9008 (mb_detect_encoding(): wrong results with null $encodings).

ext/dba/dba.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
860860
fcntl(info->fd, F_SETFL, flags & ~O_APPEND);
861861
#elif defined(PHP_WIN32)
862862
} else if (modenr == DBA_CREAT && need_creation && !restarted) {
863-
bool close_both;
864-
865-
close_both = (info->fp != info->lock.fp);
866-
php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
867-
if (close_both) {
863+
if (info->lock.fp != NULL) {
864+
php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
865+
}
866+
if (info->fp != info->lock.fp) {
868867
php_stream_free(info->fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
869868
}
870869
info->fp = NULL;

ext/dba/tests/gh9155.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug GH-9155 (dba_open("non-existing", "c-", "flatfile") segfaults)
3+
--EXTENSIONS--
4+
dba
5+
--SKIPIF--
6+
<?php
7+
$handler = "flatfile";
8+
require_once(__DIR__ .'/skipif.inc');
9+
?>
10+
--FILE--
11+
<?php
12+
13+
require_once(__DIR__ .'/test.inc');
14+
15+
$db = dba_open($db_filename, 'c-', 'flatfile');
16+
var_dump($db);
17+
?>
18+
--CLEAN--
19+
<?php
20+
require_once(__DIR__ .'/clean.inc');
21+
?>
22+
--EXPECTF--
23+
resource(%d) of type (dba)

0 commit comments

Comments
 (0)