Skip to content

Commit 89216b2

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-9155: dba_open("non-existing", "c-", "flatfile") segfaults
2 parents 5d62cfb + cf1664e commit 89216b2

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

ext/dba/dba.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
824824
fcntl(info->fd, F_SETFL, flags & ~O_APPEND);
825825
#elif defined(PHP_WIN32)
826826
} else if (modenr == DBA_CREAT && need_creation && !restarted) {
827-
bool close_both;
828-
829-
close_both = (info->fp != info->lock.fp);
830-
php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
831-
if (close_both) {
827+
if (info->lock.fp != NULL) {
828+
php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
829+
}
830+
if (info->fp != info->lock.fp) {
832831
php_stream_free(info->fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
833832
}
834833
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)