Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ext/standard/tests/streams/gh25816.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-25816 (stream_lock() can close the stream while it is in use)
--CREDITS--
snowjeon2
--FILE--
<?php
class W {
public $context;
function stream_open($path, $mode, $options, &$opened_path) { return true; }
function stream_lock($operation) { global $s; fclose($s); return true; }
}
stream_wrapper_register("lock", "W");
$s = fopen("lock://", "r");
var_dump(flock($s, LOCK_EX));
var_dump(is_resource($s));
?>
--EXPECTF--
Warning: fclose(): cannot close the provided stream, as it must not be manually closed in %s on line %d
bool(true)
bool(true)
13 changes: 11 additions & 2 deletions main/streams/userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,17 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
case PHP_STREAM_OPTION_CHECK_LIVENESS:
return user_stream_set_check_liveliness(us);

case PHP_STREAM_OPTION_LOCKING:
return user_stream_set_locking(us, value);
case PHP_STREAM_OPTION_LOCKING: {
uint32_t orig_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE;
stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;

int ret = user_stream_set_locking(us, value);

stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE;
stream->flags |= orig_no_fclose;

return ret;
}

case PHP_STREAM_OPTION_TRUNCATE_API:
return user_stream_set_truncation(us, value, ptrparam);
Expand Down
Loading