Skip to content

Commit 5bb11fe

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

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

ext/spl/spl_directory.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,17 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
522522
break;
523523
}
524524

525+
char *open_mode = "r";
526+
size_t open_mode_len = 1;
527+
zval *resource = NULL;
528+
529+
if (zend_parse_parameters(num_args, "|sbr",
530+
&open_mode, &open_mode_len, &use_include_path, &resource) == FAILURE
531+
) {
532+
zend_restore_error_handling(&error_handling);
533+
return NULL;
534+
}
535+
525536
intern = spl_filesystem_from_obj(spl_filesystem_object_new_ex(ce));
526537

527538
ZVAL_OBJ(return_value, &intern->std);
@@ -530,7 +541,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
530541

531542
if (ce->constructor->common.scope != spl_ce_SplFileObject) {
532543
ZVAL_STRINGL(&arg1, source->file_name, source->file_name_len);
533-
ZVAL_STRINGL(&arg2, "r", 1);
544+
ZVAL_STRINGL(&arg2, open_mode, open_mode_len);
534545
zend_call_method_with_2_params(Z_OBJ_P(return_value), ce, &ce->constructor, "__construct", NULL, &arg1, &arg2);
535546
zval_ptr_dtor(&arg1);
536547
zval_ptr_dtor(&arg2);
@@ -540,19 +551,9 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
540551
intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len);
541552
intern->_path = estrndup(intern->_path, intern->_path_len);
542553

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-
}
554+
intern->u.file.open_mode = open_mode;
555+
intern->u.file.open_mode_len = open_mode_len;
556+
intern->u.file.zcontext = resource;
556557

557558
if (spl_filesystem_file_open(intern, use_include_path, 0) == FAILURE) {
558559
zend_restore_error_handling(&error_handling);

0 commit comments

Comments
 (0)