Skip to content

Commit e635857

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-16390: dba_open() can segfault for "pathless" streams
2 parents d6bac2f + d3b0efe commit e635857

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ PHP NEWS
2222
. Fixed bug GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset).
2323
(cmb)
2424

25+
- DBA:
26+
. Fixed bug GH-16390 (dba_open() can segfault for "pathless" streams). (cmb)
27+
2528
- DOM:
2629
. Fixed bug GH-16316 (DOMXPath breaks when not initialized properly).
2730
(nielsdos)

ext/dba/dba.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
788788
info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, &opened_path);
789789
if (info->lock.fp) {
790790
if (is_db_lock) {
791-
ZEND_ASSERT(opened_path);
792-
/* replace the path info with the real path of the opened file */
793-
zend_string_release(info->path);
794-
info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
791+
if (opened_path) {
792+
/* replace the path info with the real path of the opened file */
793+
zend_string_release_ex(info->path, persistent);
794+
info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
795+
} else {
796+
error = "Unable to determine path for locking";
797+
}
795798
}
796799
}
797800
if (opened_path) {
@@ -807,10 +810,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
807810
FREE_PERSISTENT_RESOURCE_KEY();
808811
RETURN_FALSE;
809812
}
810-
if (!php_stream_supports_lock(info->lock.fp)) {
813+
if (!error && !php_stream_supports_lock(info->lock.fp)) {
811814
error = "Stream does not support locking";
812815
}
813-
if (php_stream_lock(info->lock.fp, lock_mode)) {
816+
if (!error && php_stream_lock(info->lock.fp, lock_mode)) {
814817
error = "Unable to establish lock"; /* force failure exit */
815818
}
816819
}

ext/dba/tests/gh16390.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-16390 (dba_open() can segfault for "pathless" streams)
3+
--EXTENSIONS--
4+
dba
5+
--FILE--
6+
<?php
7+
$file = 'data:text/plain;z=y;uri=eviluri;mediatype=wut?;mediatype2=hello,somedata';
8+
$db = dba_open($file, 'c', 'inifile');
9+
?>
10+
--EXPECTF--
11+
Warning: dba_open(): Driver initialization failed for handler: inifile: Unable to determine path for locking in %s on line %d

0 commit comments

Comments
 (0)