Skip to content

Commit 03e5ba7

Browse files
committed
Try to fix ZPP of SplFileInfo::openFile()
1 parent 059c9b5 commit 03e5ba7

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

ext/spl/spl_directory.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,22 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
528528

529529
spl_filesystem_object_get_file_name(source);
530530

531+
char *open_mode = "r";
532+
size_t open_mode_len = 1;
533+
zval *resource = NULL;
534+
535+
if (num_args && zend_parse_parameters(num_args, "|sbr",
536+
&open_mode, &open_mode_len, &use_include_path, &resource) == FAILURE
537+
) {
538+
zend_restore_error_handling(&error_handling);
539+
zval_ptr_dtor(return_value);
540+
ZVAL_NULL(return_value);
541+
return NULL;
542+
}
543+
531544
if (ce->constructor->common.scope != spl_ce_SplFileObject) {
532545
ZVAL_STRINGL(&arg1, source->file_name, source->file_name_len);
533-
ZVAL_STRINGL(&arg2, "r", 1);
546+
ZVAL_STRINGL(&arg2, open_mode, open_mode_len);
534547
zend_call_method_with_2_params(Z_OBJ_P(return_value), ce, &ce->constructor, "__construct", NULL, &arg1, &arg2);
535548
zval_ptr_dtor(&arg1);
536549
zval_ptr_dtor(&arg2);
@@ -540,19 +553,9 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
540553
intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len);
541554
intern->_path = estrndup(intern->_path, intern->_path_len);
542555

543-
intern->u.file.open_mode = "r";
544-
intern->u.file.open_mode_len = 1;
545-
546-
if (num_args && zend_parse_parameters(num_args, "|sbr",
547-
&intern->u.file.open_mode, &intern->u.file.open_mode_len,
548-
&use_include_path, &intern->u.file.zcontext) == FAILURE) {
549-
zend_restore_error_handling(&error_handling);
550-
intern->u.file.open_mode = NULL;
551-
intern->file_name = NULL;
552-
zval_ptr_dtor(return_value);
553-
ZVAL_NULL(return_value);
554-
return NULL;
555-
}
556+
intern->u.file.open_mode = open_mode;
557+
intern->u.file.open_mode_len = open_mode_len;
558+
intern->u.file.zcontext = resource;
556559

557560
if (spl_filesystem_file_open(intern, use_include_path, 0) == FAILURE) {
558561
zend_restore_error_handling(&error_handling);

0 commit comments

Comments
 (0)