Skip to content

Commit 4c7044e

Browse files
committed
Fix now manual stream checks
1 parent 72dc45c commit 4c7044e

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

ext/libxml/libxml.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,17 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
771771
} else if (Z_TYPE(retval) == IS_RESOURCE) {
772772
php_stream *stream;
773773
php_stream_from_zval_no_verify(stream, &retval);
774-
if (stream == NULL) {
774+
if (UNEXPECTED(stream == NULL)) {
775+
zval callable;
776+
zend_get_callable_zval_from_fcc(&LIBXML(entity_loader_callback), &callable);
777+
778+
zend_string *callable_name = zend_get_callable_name(&callable);
775779
php_libxml_ctx_error(context,
776780
"The user entity loader callback '%s' has returned a "
777781
"resource, but it is not a stream",
778-
ZSTR_VAL(LIBXML(entity_loader_callback).function_handler->common.function_name));
782+
ZSTR_VAL(callable_name));
783+
zend_string_release(callable_name);
784+
zval_dtor(&callable);
779785
} else {
780786
/* TODO: allow storing the encoding in the stream context? */
781787
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;

ext/libxml/tests/libxml_get_external_entity_loader_error_callback_name.phpt

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ try {
3636
}
3737

3838
?>
39-
--EXPECT--
40-
string(73) "DOMDocument::validate(): supplied resource is not a valid stream resource"
39+
--EXPECTF--
40+
Warning: DOMDocument::validate(): The user entity loader callback 'Handler::handle' has returned a resource, but it is not a streamFailed to load external entity "-//FOO/BAR" in %s on line %d
41+
42+
Warning: DOMDocument::validate(): Could not load the external subset "http://example.com/foobar" in %s on line %d
43+
bool(false)

ext/posix/posix.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *ret) /* {{{ */
422422

423423
php_stream_from_zval_no_verify(stream, zfp);
424424

425-
if (stream == NULL) {
425+
if (UNEXPECTED(stream == NULL)) {
426+
zend_argument_type_error(1, "must be an open stream resource");
426427
return FAILURE;
427428
}
428429

0 commit comments

Comments
 (0)