From: Nikita Popov Date: Tue, 29 Sep 2020 12:48:31 +0000 (+0200) Subject: Don't accept dir handle in Directory methods X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59aa21c735190a978c976467560b270855eb92e9;p=php Don't accept dir handle in Directory methods This is an artifact of the shared implementation with readdir() etc. The method versions should not accept an explicit dir handle, as they work on the dir handle from the object. --- diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 98bff12fc2..c1c264d1f0 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -59,30 +59,32 @@ php_dir_globals dir_globals; static zend_class_entry *dir_class_entry_ptr; #define FETCH_DIRP() \ - ZEND_PARSE_PARAMETERS_START(0, 1) \ - Z_PARAM_OPTIONAL \ - Z_PARAM_RESOURCE_OR_NULL(id) \ - ZEND_PARSE_PARAMETERS_END(); \ - if (!id) { \ - myself = getThis(); \ - if (myself) { \ - if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \ - zend_throw_error(NULL, "Unable to find my handle property"); \ - RETURN_THROWS(); \ - } \ - if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \ + myself = getThis(); \ + if (!myself) { \ + ZEND_PARSE_PARAMETERS_START(0, 1) \ + Z_PARAM_OPTIONAL \ + Z_PARAM_RESOURCE_OR_NULL(id) \ + ZEND_PARSE_PARAMETERS_END(); \ + if (id) { \ + if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \ RETURN_THROWS(); \ } \ } else { \ if (!DIRG(default_dir)) { \ zend_type_error("No resource supplied"); \ RETURN_THROWS(); \ - } else if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \ + } \ + if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \ RETURN_THROWS(); \ } \ } \ } else { \ - if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \ + ZEND_PARSE_PARAMETERS_NONE(); \ + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \ + zend_throw_error(NULL, "Unable to find my handle property"); \ + RETURN_THROWS(); \ + } \ + if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \ RETURN_THROWS(); \ } \ } diff --git a/ext/standard/dir.stub.php b/ext/standard/dir.stub.php index fb129acaef..9904c6bc99 100755 --- a/ext/standard/dir.stub.php +++ b/ext/standard/dir.stub.php @@ -5,23 +5,20 @@ class Directory { /** - * @param resource|null $dir_handle * @return void * @implementation-alias closedir */ - public function close($dir_handle = null) {} + public function close() {} /** - * @param resource|null $dir_handle * @return void * @implementation-alias rewinddir */ - public function rewind($dir_handle = null) {} + public function rewind() {} /** - * @param resource|null $dir_handle * @return string|false * @implementation-alias readdir */ - public function read($dir_handle = null) {} + public function read() {} } diff --git a/ext/standard/dir_arginfo.h b/ext/standard/dir_arginfo.h index a9f836d53a..a2fa03611c 100644 --- a/ext/standard/dir_arginfo.h +++ b/ext/standard/dir_arginfo.h @@ -1,8 +1,7 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d8d8c93a1659e1790b25a65d7e1d0d7430724e9d */ + * Stub hash: a715bf6a8d5fe69732623cc17f03bd463f369648 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Directory_close, 0, 0, 0) - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, dir_handle, "null") ZEND_END_ARG_INFO() #define arginfo_class_Directory_rewind arginfo_class_Directory_close diff --git a/ext/standard/tests/directory/DirectoryClass_basic_001.phpt b/ext/standard/tests/directory/DirectoryClass_basic_001.phpt index 7e3c53b797..9ccceda920 100644 --- a/ext/standard/tests/directory/DirectoryClass_basic_001.phpt +++ b/ext/standard/tests/directory/DirectoryClass_basic_001.phpt @@ -41,22 +41,19 @@ Class [ class Directory ] { - Methods [3] { Method [ public method close ] { - - Parameters [1] { - Parameter #0 [ $dir_handle = null ] + - Parameters [0] { } } Method [ public method rewind ] { - - Parameters [1] { - Parameter #0 [ $dir_handle = null ] + - Parameters [0] { } } Method [ public method read ] { - - Parameters [1] { - Parameter #0 [ $dir_handle = null ] + - Parameters [0] { } } }