Skip to content

Commit

Permalink
Check for object_init_ex() failure in user filter factory
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 7, 2019
1 parent 7d19668 commit 19e6abe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 19 additions & 0 deletions ext/standard/tests/filters/object_init_failure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Creating the stream filter object may fail
--FILE--
<?php
class SampleFilter extends php_user_filter {
private $data = \FOO;
}
stream_filter_register('sample.filter', SampleFilter::class);
try {
var_dump(file_get_contents('php://filter/read=sample.filter/resource='. __FILE__));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Warning: file_get_contents(): unable to create or locate filter "sample.filter" in %s on line %d

Warning: file_get_contents(): Unable to create filter (sample.filter) in %s on line %d
Undefined constant 'FOO'
9 changes: 6 additions & 3 deletions ext/standard/user_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,17 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
}
}

/* create the object */
if (object_init_ex(&obj, fdat->ce) == FAILURE) {
return NULL;
}

filter = php_stream_filter_alloc(&userfilter_ops, NULL, 0);
if (filter == NULL) {
zval_ptr_dtor(&obj);
return NULL;
}

/* create the object */
object_init_ex(&obj, fdat->ce);

/* filtername */
add_property_string(&obj, "filtername", (char*)filtername);

Expand Down

0 comments on commit 19e6abe

Please sign in to comment.