mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-16390: dba_open() can segfault for "pathless" streams
`dba_open()` accepts arbitrary stream wrapper paths, but unless no locking (`-`) is specified, we try to determine the underlying file path. If that fails, we need to error out. Closes GH-16498.
This commit is contained in:
parent
9ca68e037c
commit
d3b0efe9d7
3 changed files with 26 additions and 5 deletions
|
@ -772,11 +772,18 @@ restart:
|
|||
info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, &opened_path);
|
||||
if (info->lock.fp) {
|
||||
if (is_db_lock) {
|
||||
/* replace the path info with the real path of the opened file */
|
||||
pefree(info->path, persistent);
|
||||
info->path = pestrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path), persistent);
|
||||
if (opened_path) {
|
||||
/* replace the path info with the real path of the opened file */
|
||||
pefree(info->path, persistent);
|
||||
info->path = pestrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path), persistent);
|
||||
} else {
|
||||
error = "Unable to determine path for locking";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (opened_path) {
|
||||
zend_string_release_ex(opened_path, 0);
|
||||
opened_path = NULL;
|
||||
}
|
||||
}
|
||||
if (!is_db_lock) {
|
||||
|
@ -788,10 +795,10 @@ restart:
|
|||
FREE_PERSISTENT_RESOURCE_KEY();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (!php_stream_supports_lock(info->lock.fp)) {
|
||||
if (!error && !php_stream_supports_lock(info->lock.fp)) {
|
||||
error = "Stream does not support locking";
|
||||
}
|
||||
if (php_stream_lock(info->lock.fp, lock_mode)) {
|
||||
if (!error && php_stream_lock(info->lock.fp, lock_mode)) {
|
||||
error = "Unable to establish lock"; /* force failure exit */
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue