diff --git a/ext/standard/tests/streams/gh25816.phpt b/ext/standard/tests/streams/gh25816.phpt new file mode 100644 index 000000000000..33cad8869c84 --- /dev/null +++ b/ext/standard/tests/streams/gh25816.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-25816 (stream_lock() can close the stream while it is in use) +--CREDITS-- +snowjeon2 +--FILE-- + +--EXPECTF-- +Warning: fclose(): cannot close the provided stream, as it must not be manually closed in %s on line %d +bool(true) +bool(true) diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 2bf858060a4c..0b053a6ddd0c 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -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);