Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix GH-16390: dba_open() can segfault for "pathless" streams
  • Loading branch information
cmb69 committed Oct 20, 2024
2 parents c025ce4 + 2c0fd88 commit 514c2b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ext/dba/dba.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
connection->info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, &opened_path);
if (connection->info->lock.fp) {
if (is_db_lock) {
ZEND_ASSERT(opened_path);
/* replace the path info with the real path of the opened file */
zend_string_release_ex(connection->info->path, persistent);
connection->info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
if (opened_path) {
/* replace the path info with the real path of the opened file */
zend_string_release_ex(connection->info->path, persistent);
connection->info->path = php_dba_zend_string_dup_safe(opened_path, persistent);
} else {
error = "Unable to determine path for locking";
}
}
}
if (opened_path) {
Expand All @@ -862,10 +865,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
zval_ptr_dtor(return_value);
RETURN_FALSE;
}
if (!php_stream_supports_lock(connection->info->lock.fp)) {
if (!error && !php_stream_supports_lock(connection->info->lock.fp)) {
error = "Stream does not support locking";
}
if (php_stream_lock(connection->info->lock.fp, lock_mode)) {
if (!error && php_stream_lock(connection->info->lock.fp, lock_mode)) {
error = "Unable to establish lock"; /* force failure exit */
}
}
Expand Down
11 changes: 11 additions & 0 deletions ext/dba/tests/gh16390.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
GH-16390 (dba_open() can segfault for "pathless" streams)
--EXTENSIONS--
dba
--FILE--
<?php
$file = 'data:text/plain;z=y;uri=eviluri;mediatype=wut?;mediatype2=hello,somedata';
$db = dba_open($file, 'c', 'inifile');
?>
--EXPECTF--
Warning: dba_open(): Driver initialization failed for handler: inifile: Unable to determine path for locking in %s on line %d

0 comments on commit 514c2b3

Please sign in to comment.