Merge branch 'PHP-8.1'

* PHP-8.1:
  Fix GH-9155: dba_open("non-existing", "c-", "flatfile") segfaults
This commit is contained in:
Christoph M. Becker 2022-07-27 12:16:25 +02:00
commit 89216b23dd
No known key found for this signature in database
GPG Key ID: D66C9593118BCCB6
2 changed files with 27 additions and 5 deletions

View File

@ -824,11 +824,10 @@ restart:
fcntl(info->fd, F_SETFL, flags & ~O_APPEND);
#elif defined(PHP_WIN32)
} else if (modenr == DBA_CREAT && need_creation && !restarted) {
bool close_both;
close_both = (info->fp != info->lock.fp);
php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
if (close_both) {
if (info->lock.fp != NULL) {
php_stream_free(info->lock.fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
}
if (info->fp != info->lock.fp) {
php_stream_free(info->fp, persistent ? PHP_STREAM_FREE_CLOSE_PERSISTENT : PHP_STREAM_FREE_CLOSE);
}
info->fp = NULL;

23
ext/dba/tests/gh9155.phpt Normal file
View File

@ -0,0 +1,23 @@
--TEST--
Bug GH-9155 (dba_open("non-existing", "c-", "flatfile") segfaults)
--EXTENSIONS--
dba
--SKIPIF--
<?php
$handler = "flatfile";
require_once(__DIR__ .'/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__ .'/test.inc');
$db = dba_open($db_filename, 'c-', 'flatfile');
var_dump($db);
?>
--CLEAN--
<?php
require_once(__DIR__ .'/clean.inc');
?>
--EXPECTF--
resource(%d) of type (dba)