Skip to content

Commit d0630e8

Browse files
committed
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.
1 parent 7e513a5 commit d0630e8

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ PHP NEWS
4343
- Streams:
4444
. Fixed bug GH-14506 (Closing a userspace stream inside a userspace handler
4545
causes heap corruption). (nielsdos)
46+
. Avoid double conversion to string in php_userstreamop_readdir(). (nielsdos)
4647

4748
- URI:
4849
. Fixed memory management of Uri\WhatWg\Url objects. (timwolla)

main/streams/userspace.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,14 +1349,11 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co
13491349
}
13501350
// TODO: Warn/TypeError for invalid returns?
13511351
if (Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) {
1352-
zend_string *str = zval_try_get_string(&retval);
1353-
if (UNEXPECTED(str == NULL)) {
1352+
if (UNEXPECTED(!try_convert_to_string(&retval))) {
13541353
zval_ptr_dtor(&retval);
13551354
return -1;
13561355
}
1357-
convert_to_string(&retval);
1358-
PHP_STRLCPY(ent->d_name, ZSTR_VAL(str), sizeof(ent->d_name), ZSTR_LEN(str));
1359-
zend_string_release(str);
1356+
PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRLEN(retval));
13601357
ent->d_type = DT_UNKNOWN;
13611358

13621359
didread = sizeof(php_stream_dirent);

0 commit comments

Comments
 (0)