com php-src: Report error if stream_read is not impleme nted: Zend/zend_language_scanner.l main/streams/use rspace.c

From: Date: Thu, 10 Oct 2019 09:13:10 +0000
Subject: com php-src: Report error if stream_read is not impleme nted: Zend/zend_language_scanner.l main/streams/use rspace.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108851@lists.php.net to get a copy of this message
Commit: 6878c583b02b75aeab84c493d548700fb1de5976 Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 10 Oct 2019 11:12:17 +0200 Parents: 382f9b28e8390a49137fc028a0c04d291781ae7a Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6878c583b02b75aeab84c493d548700fb1de5976 Log: Report error if stream_read is not implemented We need to return -1 in this case. Slightly restructure the code to avoid unnecessary conditions. Changed paths: M Zend/zend_language_scanner.l M main/streams/userspace.c Diff: diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 13248b24204..fbcdd2c9b65 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -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)); diff --git a/main/streams/userspace.c b/main/streams/userspace.c index de3e8591e6a..af7f0b4fa28 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -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);

« previous php.cvs (#108851) next »