Skip to content

Commit 2c0fd88

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

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
@@ -28,6 +28,9 @@ PHP NEWS
2828
. Fixed bug GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset).
2929
(cmb)
3030

31+
- DBA:
32+
. Fixed bug GH-16390 (dba_open() can segfault for "pathless" streams). (cmb)
33+
3134
- DOM:
3235
. Fixed bug GH-16316 (DOMXPath breaks when not initialized properly).
3336
(nielsdos)

ext/dba/dba.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,10 +844,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
844844
connection->info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, &opened_path);
845845
if (connection->info->lock.fp) {
846846
if (is_db_lock) {
847-
ZEND_ASSERT(opened_path);
848-
/* replace the path info with the real path of the opened file */
849-
zend_string_release_ex(connection->info->path, persistent);
850-
connection->info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
847+
if (opened_path) {
848+
/* replace the path info with the real path of the opened file */
849+
zend_string_release_ex(connection->info->path, persistent);
850+
connection->info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
851+
} else {
852+
error = "Unable to determine path for locking";
853+
}
851854
}
852855
}
853856
if (opened_path) {
@@ -864,10 +867,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
864867
zval_ptr_dtor(return_value);
865868
RETURN_FALSE;
866869
}
867-
if (!php_stream_supports_lock(connection->info->lock.fp)) {
870+
if (!error && !php_stream_supports_lock(connection->info->lock.fp)) {
868871
error = "Stream does not support locking";
869872
}
870-
if (php_stream_lock(connection->info->lock.fp, lock_mode)) {
873+
if (!error && php_stream_lock(connection->info->lock.fp, lock_mode)) {
871874
error = "Unable to establish lock"; /* force failure exit */
872875
}
873876
}

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)