mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Make (DOM)XPath::quote only accept strings without NULL bytes (#13960)
* Make (DOM)XPath::quote only accept strings without NULL bytes The reason is that libxml will cut off on a NULL byte, and so strings containing NULL bytes may not be necessarily safe even when coming out of quoting. * Add test Co-authored-by: divinity76 <divinity76@gmail.com> --------- Co-authored-by: divinity76 <divinity76@gmail.com>
This commit is contained in:
17
ext/dom/tests/gh13960.phpt
Normal file
17
ext/dom/tests/gh13960.phpt
Normal file
@@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
GH-13960 (NULL bytes in XPath query)
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
$domd = new DOMDocument();
|
||||
@$domd->loadHTML("<foo>tes\x00t</foo>");
|
||||
$xp = new DOMXPath($domd);
|
||||
try {
|
||||
$xp->query("//foo[contains(text(), " . $xp->quote("tes\x00t") . ")]");
|
||||
} catch (ValueError $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
DOMXPath::quote(): Argument #1 ($str) must not contain any null bytes
|
||||
@@ -473,7 +473,7 @@ PHP_METHOD(DOMXPath, registerPhpFunctionNS)
|
||||
PHP_METHOD(DOMXPath, quote) {
|
||||
const char *input;
|
||||
size_t input_len;
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &input, &input_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &input, &input_len) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
if (memchr(input, '\'', input_len) == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user