Skip to content

Commit 514c2b3

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

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

ext/dba/dba.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
842842
connection->info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, &opened_path);
843843
if (connection->info->lock.fp) {
844844
if (is_db_lock) {
845-
ZEND_ASSERT(opened_path);
846-
/* replace the path info with the real path of the opened file */
847-
zend_string_release_ex(connection->info->path, persistent);
848-
connection->info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
845+
if (opened_path) {
846+
/* replace the path info with the real path of the opened file */
847+
zend_string_release_ex(connection->info->path, persistent);
848+
connection->info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
849+
} else {
850+
error = "Unable to determine path for locking";
851+
}
849852
}
850853
}
851854
if (opened_path) {
@@ -862,10 +865,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
862865
zval_ptr_dtor(return_value);
863866
RETURN_FALSE;
864867
}
865-
if (!php_stream_supports_lock(connection->info->lock.fp)) {
868+
if (!error && !php_stream_supports_lock(connection->info->lock.fp)) {
866869
error = "Stream does not support locking";
867870
}
868-
if (php_stream_lock(connection->info->lock.fp, lock_mode)) {
871+
if (!error && php_stream_lock(connection->info->lock.fp, lock_mode)) {
869872
error = "Unable to establish lock"; /* force failure exit */
870873
}
871874
}

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)