Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ext/dom/tests/registerPhpFunctionNS_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ dom
--FILE--
<?php

class TrampolineClass {
public function __call($name, $args) {
}
}

$doc = new DOMDocument();
$doc->loadHTML('<a href="https://PHP.net">hello</a>');

Expand All @@ -16,6 +21,18 @@ try {
echo $e->getMessage(), "\n";
}

try {
$xpath->registerPhpFunctionNS('http://php.net/xpath', 'test', [new TrampolineClass, 'test']);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
$xpath->registerPhpFunctionNS('urn:foo', '$$$', [new TrampolineClass, 'test']);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
$xpath->registerPhpFunctionNS('urn:foo', 'x:a', strtolower(...));
} catch (ValueError $e) {
Expand All @@ -37,6 +54,8 @@ try {
?>
--EXPECT--
DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xpath" because it is reserved by PHP
DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xpath" because it is reserved by PHP
DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must be a valid callback name
DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must be a valid callback name
DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must not contain any null bytes
DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not contain any null bytes
7 changes: 5 additions & 2 deletions ext/dom/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,22 @@ PHP_METHOD(DOMXPath, registerPhpFunctionNS)
ZEND_PARSE_PARAMETERS_END();

if (zend_string_equals_literal(namespace, "http://php.net/xpath")) {
zend_release_fcall_info_cache(&fcc);
zend_argument_value_error(1, "must not be \"http://php.net/xpath\" because it is reserved by PHP");
RETURN_THROWS();
}

php_dom_xpath_callbacks_update_single_method_handler(
if (php_dom_xpath_callbacks_update_single_method_handler(
&intern->xpath_callbacks,
intern->dom.ptr,
namespace,
name,
&fcc,
PHP_DOM_XPATH_CALLBACK_NAME_VALIDATE_NCNAME,
dom_xpath_register_func_in_ctx
);
) != SUCCESS) {
zend_release_fcall_info_cache(&fcc);
}
}

/* {{{ */
Expand Down
19 changes: 19 additions & 0 deletions ext/xsl/tests/registerPHPFunctionNS_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ xsl
--FILE--
<?php

class TrampolineClass {
public function __call($name, $args) {
}
}

require __DIR__ . '/xpath_callables.inc';

try {
Expand All @@ -13,6 +18,18 @@ try {
echo $e->getMessage(), "\n";
}

try {
createProcessor([])->registerPhpFunctionNS('http://php.net/xsl', 'test', [new TrampolineClass, 'test']);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
createProcessor([])->registerPhpFunctionNS('urn:foo', '$$$', [new TrampolineClass, 'test']);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
createProcessor([])->registerPhpFunctionNS('urn:foo', 'x:a', strtolower(...));
} catch (ValueError $e) {
Expand All @@ -34,6 +51,8 @@ try {
?>
--EXPECT--
XSLTProcessor::registerPHPFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xsl" because it is reserved by PHP
XSLTProcessor::registerPHPFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xsl" because it is reserved by PHP
XSLTProcessor::registerPHPFunctionNS(): Argument #2 ($name) must be a valid callback name
XSLTProcessor::registerPHPFunctionNS(): Argument #2 ($name) must be a valid callback name
XSLTProcessor::registerPHPFunctionNS(): Argument #2 ($name) must not contain any null bytes
XSLTProcessor::registerPHPFunctionNS(): Argument #1 ($namespaceURI) must not contain any null bytes
7 changes: 5 additions & 2 deletions ext/xsl/xsltprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,19 +707,22 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctionNS)
ZEND_PARSE_PARAMETERS_END();

if (zend_string_equals_literal(namespace, "http://php.net/xsl")) {
zend_release_fcall_info_cache(&fcc);
zend_argument_value_error(1, "must not be \"http://php.net/xsl\" because it is reserved by PHP");
RETURN_THROWS();
}

php_dom_xpath_callbacks_update_single_method_handler(
if (php_dom_xpath_callbacks_update_single_method_handler(
&intern->xpath_callbacks,
NULL,
namespace,
name,
&fcc,
PHP_DOM_XPATH_CALLBACK_NAME_VALIDATE_NCNAME,
NULL
);
) != SUCCESS) {
zend_release_fcall_info_cache(&fcc);
}
}

/* {{{ */
Expand Down
Loading