mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Avoid double conversion to string in php_userstreamop_readdir()
The string is converted twice for some reason. This is pointless, and furthermore, this is observable in userspace code when dealing with Stringable objects. Closes GH-19713.
This commit is contained in:
1
NEWS
1
NEWS
@@ -43,6 +43,7 @@ PHP NEWS
|
||||
- Streams:
|
||||
. Fixed bug GH-14506 (Closing a userspace stream inside a userspace handler
|
||||
causes heap corruption). (nielsdos)
|
||||
. Avoid double conversion to string in php_userstreamop_readdir(). (nielsdos)
|
||||
|
||||
- URI:
|
||||
. Fixed memory management of Uri\WhatWg\Url objects. (timwolla)
|
||||
|
||||
@@ -1349,14 +1349,11 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co
|
||||
}
|
||||
// TODO: Warn/TypeError for invalid returns?
|
||||
if (Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) {
|
||||
zend_string *str = zval_try_get_string(&retval);
|
||||
if (UNEXPECTED(str == NULL)) {
|
||||
if (UNEXPECTED(!try_convert_to_string(&retval))) {
|
||||
zval_ptr_dtor(&retval);
|
||||
return -1;
|
||||
}
|
||||
convert_to_string(&retval);
|
||||
PHP_STRLCPY(ent->d_name, ZSTR_VAL(str), sizeof(ent->d_name), ZSTR_LEN(str));
|
||||
zend_string_release(str);
|
||||
PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRLEN(retval));
|
||||
ent->d_type = DT_UNKNOWN;
|
||||
|
||||
didread = sizeof(php_stream_dirent);
|
||||
|
||||
Reference in New Issue
Block a user