]> granicus.if.org Git - php/commitdiff
Report error if stream_read is not implemented
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Oct 2019 09:12:17 +0000 (11:12 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 10 Oct 2019 09:13:10 +0000 (11:13 +0200)
We need to return -1 in this case. Slightly restructure the code
to avoid unnecessary conditions.

Zend/zend_language_scanner.l
main/streams/userspace.c

index 13248b242040e636ad37563508b6b0daec3f709d..fbcdd2c9b650f44986c46d6415b8e95dcb329e06 100644 (file)
@@ -523,6 +523,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
                return FAILURE;
        }
 
+       ZEND_ASSERT(!EG(exception) && "stream_fixup() should have failed");
        zend_llist_add_element(&CG(open_files), file_handle);
        if (file_handle->handle.stream.handle >= (void*)file_handle && file_handle->handle.stream.handle <= (void*)(file_handle+1)) {
                zend_file_handle *fh = (zend_file_handle*)zend_llist_get_last(&CG(open_files));
index de3e8591e6aaa3290d24e029e29c462275152eb9..af7f0b4fa281a26825c720d29680ef2d2598dfcc 100644 (file)
@@ -671,27 +671,28 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
                return -1;
        }
 
-       if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
-               if (Z_TYPE(retval) == IS_FALSE) {
-                       return -1;
-               }
-
-               if (!try_convert_to_string(&retval)) {
-                       return -1;
-               }
-
-               didread = Z_STRLEN(retval);
-               if (didread > count) {
-                       php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
-                                       us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
-                       didread = count;
-               }
-               if (didread > 0)
-                       memcpy(buf, Z_STRVAL(retval), didread);
-       } else if (call_result == FAILURE) {
+       if (call_result == FAILURE) {
                php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
                                us->wrapper->classname);
+               return -1;
+       }
+
+       if (Z_TYPE(retval) == IS_FALSE) {
+               return -1;
+       }
+
+       if (!try_convert_to_string(&retval)) {
+               return -1;
+       }
+
+       didread = Z_STRLEN(retval);
+       if (didread > count) {
+               php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
+                               us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
+               didread = count;
        }
+       if (didread > 0)
+               memcpy(buf, Z_STRVAL(retval), didread);
 
        zval_ptr_dtor(&retval);
        ZVAL_UNDEF(&retval);