diff options
| author | Felipe Pena <felipe@php.net> | 2011-03-23 22:46:04 +0000 |
|---|---|---|
| committer | Felipe Pena <felipe@php.net> | 2011-03-23 22:46:04 +0000 |
| commit | 39e0aa4dc6f66ac00cc6e1a86ea9d71bb5f3520f (patch) | |
| tree | 8b97a4c763c124111af5812d090b4592f094f3fe /ext | |
| parent | 0a4d7e88c90b8e65c3c43fc815b4759391190a62 (diff) | |
| download | php-git-39e0aa4dc6f66ac00cc6e1a86ea9d71bb5f3520f.tar.gz | |
- Fixed bug #54292 (Wrong parameter causes crash in SplFileObject::__construct())
Diffstat (limited to 'ext')
| -rwxr-xr-x | ext/spl/spl_directory.c | 13 | ||||
| -rw-r--r-- | ext/spl/tests/bug54292.phpt | 14 |
2 files changed, 24 insertions, 3 deletions
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-- +<?php + +try { + new SplFileObject('foo', array()); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +?> +--EXPECTF-- +string(74) "SplFileObject::__construct() expects parameter 2 to be string, array given" |
