Skip to content

Fix: Checking if a stream is castable should not emit warnings for user defined streams #10435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
20 changes: 14 additions & 6 deletions main/streams/userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,8 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
php_stream * intstream = NULL;
int call_result;
int ret = FAILURE;
/* If we are checking if the stream can cast, no return pointer is provided, so do not emit errors */
bool report_errors = retptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit hacky but I guess it's still better that hold call state in the stream struct so I'm cool with this. Not sure if we need temp var but not a big issue with that either...


ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1);

Expand All @@ -1400,22 +1402,28 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)

do {
if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
ZSTR_VAL(us->wrapper->ce->name));
if (report_errors) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!",
ZSTR_VAL(us->wrapper->ce->name));
}
break;
}
if (!zend_is_true(&retval)) {
break;
}
php_stream_from_zval_no_verify(intstream, &retval);
if (!intstream) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
ZSTR_VAL(us->wrapper->ce->name));
if (report_errors) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource",
ZSTR_VAL(us->wrapper->ce->name));
}
break;
}
if (intstream == stream) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
ZSTR_VAL(us->wrapper->ce->name));
if (report_errors) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself",
ZSTR_VAL(us->wrapper->ce->name));
}
intstream = NULL;
break;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/output/stream_isatty_non_castable_userwrapper.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Non castable user-space streams (stream_cast())
--FILE--
<?php
class test_wrapper {
public $context;
public $return_value;
function stream_open($path, $mode, $openedpath) {
return true;
}
function stream_eof() {
return false;
}
}

stream_wrapper_register('test', 'test_wrapper');
$fd = fopen("test://foo","r");
var_dump(stream_isatty($fd));

?>
--EXPECT--
bool(false)