1
0
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:
Niels Dossche
2025-09-04 22:21:04 +02:00
parent 7e513a5101
commit d0630e850b
2 changed files with 3 additions and 5 deletions

1
NEWS
View File

@@ -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)

View File

@@ -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);