Skip to content

Commit 15e23da

Browse files
committed
Prevent dangling pointers
1 parent 28baa7f commit 15e23da

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ext/spl/spl_directory.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2042,16 +2042,22 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
20422042
PHP_METHOD(SplFileObject, __construct)
20432043
{
20442044
spl_filesystem_object *intern = spl_filesystem_from_obj(Z_OBJ_P(ZEND_THIS));
2045+
zend_string *file_name = NULL;
20452046
zend_string *open_mode = ZSTR_CHAR('r');
2047+
zval *stream_context = NULL;
20462048
bool use_include_path = 0;
20472049
size_t path_len;
20482050
zend_error_handling error_handling;
20492051

2050-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|Sbr!", &intern->file_name, &open_mode, &use_include_path, &intern->u.file.zcontext) == FAILURE) {
2052+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|Sbr!", &file_name, &open_mode, &use_include_path, &stream_context) == FAILURE) {
20512053
RETURN_THROWS();
20522054
}
20532055

2056+
// TODO This should probably take a copy:
2057+
// intern->file_name = zend_string_copy(file_name);
2058+
intern->file_name = file_name;
20542059
intern->u.file.open_mode = zend_string_copy(open_mode);
2060+
intern->u.file.zcontext = stream_context;
20552061

20562062
/* spl_filesystem_file_open() can generate E_WARNINGs which we want to promote to exceptions */
20572063
zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);

0 commit comments

Comments
 (0)