com php-src: Fix #67626: ext/standard/tests/streams/bug67626.phpt main/streams/userspace.c
| From: | Stanislav Malyshev | Date: | Mon, 09 Mar 2015 06:40:55 +0000 |
| Subject: | com php-src: Fix #67626: ext/standard/tests/streams/bug67626.phpt main/streams/userspace.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85382@lists.php.net to get a copy of this message | ||
Commit: 7d47d9fe23274d750bee90a4d7f2251ebaaa4e1a
Author: Julien Pauli <jpauli@php.net> Tue, 15 Jul 2014 17:18:56 +0200
Committer: Stanislav Malyshev <stas@php.net> Sun, 8 Mar 2015 23:40:55 -0700
Parents: 7684d72df8a55f9c23e80091c89818d870d7a108
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7d47d9fe23274d750bee90a4d7f2251ebaaa4e1a
Log:
Fix #67626
Bugs:
https://bugs.php.net/67626
Changed paths:
A ext/standard/tests/streams/bug67626.phpt
M main/streams/userspace.c
Diff:
diff --git a/ext/standard/tests/streams/bug67626.phpt b/ext/standard/tests/streams/bug67626.phpt
new file mode 100644
index 0000000..67c2c3f
--- /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 0152b88..e4a2663 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -646,6 +646,11 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf,
size_t
zval_ptr_dtor(&zbufptr);
didwrite = 0;
+
+ if (EG(exception)) {
+ return 0;
+ }
+
if (call_result == SUCCESS && retval != NULL) {
convert_to_long(retval);
didwrite = Z_LVAL_P(retval);
@@ -693,6 +698,12 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
1, args,
0, NULL TSRMLS_CC);
+ zval_ptr_dtor(&zcount);
+
+ if (EG(exception)) {
+ return -1;
+ }
+
if (call_result == SUCCESS && retval != NULL) {
convert_to_string(retval);
didread = Z_STRLEN_P(retval);
@@ -707,7 +718,6 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " is not
implemented!",
us->wrapper->classname);
}
- zval_ptr_dtor(&zcount);
if (retval) {
zval_ptr_dtor(&retval);