summaryrefslogtreecommitdiff
path: root/ext/spl/spl_directory.c
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2014-07-26 19:37:37 -0700
committerStanislav Malyshev <stas@php.net>2014-07-26 19:37:37 -0700
commit47a12117c39bc2f5e836ef79e69e9f191e2e8363 (patch)
tree741a36823abbf77a4e43f2d4237afac1fceee96b /ext/spl/spl_directory.c
parentfaaa0ffdc4a11d4720f64c4901cc5925b21fee1a (diff)
parent90a0d58af81b03dfc8c1b0be4efa71cffc732aef (diff)
downloadphp-git-47a12117c39bc2f5e836ef79e69e9f191e2e8363.tar.gz
Merge branch 'PHP-5.6'
* PHP-5.6: Fix SPL objects initialization checks
Diffstat (limited to 'ext/spl/spl_directory.c')
-rw-r--r--ext/spl/spl_directory.c97
1 files changed, 91 insertions, 6 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 0d5cccf0c9..c2f67ac395 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -1617,7 +1617,7 @@ SPL_METHOD(GlobIterator, count)
return;
}
- if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
+ if (intern->u.dir.dirp && php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL));
} else {
/* should not happen */
@@ -2098,7 +2098,7 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
zend_fcall_info fci;
zend_fcall_info_cache fcic;
zval z_fname;
- zval * zresource_ptr = &intern->u.file.zresource, *retval;
+ zval * zresource_ptr = &intern->u.file.zresource, *retval = NULL;
int result;
int num_args = pass_num_args + (arg2 ? 2 : 1);
@@ -2132,7 +2132,7 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
result = zend_call_function(&fci, &fcic TSRMLS_CC);
- if (result == FAILURE) {
+ if (result == FAILURE || retval == NULL) {
RETVAL_FALSE;
} else {
ZVAL_ZVAL(return_value, retval, 1, 1);
@@ -2265,6 +2265,10 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object
static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
{
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
if (-1 == php_stream_rewind(intern->u.file.stream)) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot rewind file %s", intern->file_name);
} else {
@@ -2397,6 +2401,11 @@ SPL_METHOD(SplFileObject, eof)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
RETURN_BOOL(php_stream_eof(intern->u.file.stream));
} /* }}} */
@@ -2413,6 +2422,9 @@ SPL_METHOD(SplFileObject, valid)
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
RETURN_BOOL(intern->u.file.current_line || intern->u.file.current_zval);
} else {
+ if(!intern->u.file.stream) {
+ RETURN_FALSE;
+ }
RETVAL_BOOL(!php_stream_eof(intern->u.file.stream));
}
} /* }}} */
@@ -2427,6 +2439,11 @@ SPL_METHOD(SplFileObject, fgets)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (spl_filesystem_file_read(intern, 0 TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
@@ -2443,6 +2460,11 @@ SPL_METHOD(SplFileObject, current)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (!intern->u.file.current_line && !intern->u.file.current_zval) {
spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
}
@@ -2585,6 +2607,12 @@ SPL_METHOD(SplFileObject, fgetcsv)
int d_len = 0, e_len = 0, esc_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
+
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
switch(ZEND_NUM_ARGS())
{
case 3:
@@ -2726,6 +2754,11 @@ SPL_METHOD(SplFileObject, fflush)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
RETURN_BOOL(!php_stream_flush(intern->u.file.stream));
} /* }}} */
@@ -2734,7 +2767,14 @@ SPL_METHOD(SplFileObject, fflush)
SPL_METHOD(SplFileObject, ftell)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long ret = php_stream_tell(intern->u.file.stream);
+ long ret;
+
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
+ ret = php_stream_tell(intern->u.file.stream);
if (ret == -1) {
RETURN_FALSE;
@@ -2754,6 +2794,11 @@ SPL_METHOD(SplFileObject, fseek)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
spl_filesystem_file_free_line(intern TSRMLS_CC);
RETURN_LONG(php_stream_seek(intern->u.file.stream, pos, whence));
} /* }}} */
@@ -2766,6 +2811,11 @@ SPL_METHOD(SplFileObject, fgetc)
char buf[2];
int result;
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
spl_filesystem_file_free_line(intern TSRMLS_CC);
result = php_stream_getc(intern->u.file.stream);
@@ -2791,6 +2841,11 @@ SPL_METHOD(SplFileObject, fgetss)
zval *arg2 = NULL;
MAKE_STD_ZVAL(arg2);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (intern->u.file.max_line_len > 0) {
ZVAL_LONG(arg2, intern->u.file.max_line_len);
} else {
@@ -2811,6 +2866,11 @@ SPL_METHOD(SplFileObject, fpassthru)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
RETURN_LONG(php_stream_passthru(intern->u.file.stream));
} /* }}} */
@@ -2820,6 +2880,11 @@ SPL_METHOD(SplFileObject, fscanf)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
spl_filesystem_file_free_line(intern TSRMLS_CC);
intern->u.file.current_line_num++;
@@ -2840,6 +2905,11 @@ SPL_METHOD(SplFileObject, fwrite)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (ZEND_NUM_ARGS() > 1) {
str_len = MAX(0, MIN(length, str_len));
}
@@ -2859,6 +2929,11 @@ SPL_METHOD(SplFileObject, fread)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (length <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
@@ -2888,6 +2963,11 @@ SPL_METHOD(SplFileObject, ftruncate)
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (!php_stream_truncate_supported(intern->u.file.stream)) {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't truncate file %s", intern->file_name);
RETURN_FALSE;
@@ -2902,15 +2982,20 @@ SPL_METHOD(SplFileObject, seek)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
long line_pos;
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &line_pos) == FAILURE) {
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (line_pos < 0) {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't seek file %s to negative line %ld", intern->file_name, line_pos);
RETURN_FALSE;
}
-
+
spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC);
while(intern->u.file.current_line_num < line_pos) {