summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Pauli <jpauli@php.net>2014-07-15 17:18:56 +0200
committerStanislav Malyshev <stas@php.net>2015-03-08 23:45:11 -0700
commit2f06413340655a76024612c5c861b4b8f43555e1 (patch)
tree6de3ce414c17685d04d3582dfb4ef400c3c1f313
parent37ecfdad09767773dfacf478e0c5a66a01f66dca (diff)
downloadphp-git-2f06413340655a76024612c5c861b4b8f43555e1.tar.gz
Fix #67626
-rw-r--r--ext/standard/tests/streams/bug67626.phpt45
-rw-r--r--main/streams/userspace.c14
2 files changed, 57 insertions, 2 deletions
diff --git a/ext/standard/tests/streams/bug67626.phpt b/ext/standard/tests/streams/bug67626.phpt
new file mode 100644
index 0000000000..67c2c3f8e0
--- /dev/null
+++ b/ext/standard/tests/streams/bug67626.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #67626: Exceptions not properly handled in user stream handlers
+--FILE--
+<?php
+class MyStream
+{
+ public function stream_open() { return true; }
+
+ public function stream_read()
+ {
+ throw new Exception('stream_read_exception');
+ return 'read';
+ }
+
+ public function stream_eof()
+ {
+ return true;
+ }
+
+ public function stream_write()
+ {
+ throw new Exception('stream_write_exception');
+ return 42;
+ }
+}
+
+stream_wrapper_register("my", "MyStream");
+
+$fp = fopen('my://foobar', 'r+');
+
+try {
+ fread($fp, 42);
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
+echo "\n";
+try {
+ fwrite($fp, 'foobar');
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
+?>
+--EXPECTF--
+stream_read_exception
+stream_write_exception \ No newline at end of file
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index 33dbbf8d67..69f4fa4029 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -607,6 +607,11 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t
zval_ptr_dtor(&func_name);
didwrite = 0;
+
+ if (EG(exception)) {
+ return 0;
+ }
+
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
convert_to_long(&retval);
didwrite = Z_LVAL(retval);
@@ -650,6 +655,13 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count)
1, args,
0, NULL);
+ zval_ptr_dtor(&args[0);
+ zval_ptr_dtor(&func_name);
+
+ if (EG(exception)) {
+ return -1;
+ }
+
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
convert_to_string(&retval);
didread = Z_STRLEN(retval);
@@ -664,11 +676,9 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count)
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
us->wrapper->classname);
}
- zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&retval);
ZVAL_UNDEF(&retval);
- zval_ptr_dtor(&func_name);
/* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */