From 39e0aa4dc6f66ac00cc6e1a86ea9d71bb5f3520f Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 23 Mar 2011 22:46:04 +0000 Subject: [PATCH] - Fixed bug #54292 (Wrong parameter causes crash in SplFileObject::__construct()) --- ext/spl/spl_directory.c | 13 ++++++++++--- ext/spl/tests/bug54292.phpt | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 ext/spl/tests/bug54292.phpt diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 5e38b5c583..ab7bfe5142 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -2211,17 +2211,24 @@ SPL_METHOD(SplFileObject, __construct) zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC); - intern->u.file.open_mode = "r"; - intern->u.file.open_mode_len = 1; + intern->u.file.open_mode = NULL; + intern->u.file.open_mode_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sbr", &intern->file_name, &intern->file_name_len, &intern->u.file.open_mode, &intern->u.file.open_mode_len, - &use_include_path, &intern->u.file.zcontext) == FAILURE) { + &use_include_path, &intern->u.file.zcontext) == FAILURE) { + intern->u.file.open_mode = NULL; + intern->file_name = NULL; zend_restore_error_handling(&error_handling TSRMLS_CC); return; } + if (intern->u.file.open_mode == NULL) { + intern->u.file.open_mode = "r"; + intern->u.file.open_mode_len = 1; + } + if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == SUCCESS) { tmp_path_len = strlen(intern->u.file.stream->orig_path); diff --git a/ext/spl/tests/bug54292.phpt b/ext/spl/tests/bug54292.phpt new file mode 100644 index 0000000000..d9175f7e6f --- /dev/null +++ b/ext/spl/tests/bug54292.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #54292 (Wrong parameter causes crash in SplFileObject::__construct()) +--FILE-- +getMessage()); +} + +?> +--EXPECTF-- +string(74) "SplFileObject::__construct() expects parameter 2 to be string, array given" -- 2.50.1