Skip to content

Commit a136117

Browse files
nielsdosdivinity76
andauthored
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 <[email protected]> --------- Co-authored-by: divinity76 <[email protected]>
1 parent 8ce9f2e commit a136117

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ext/dom/tests/gh13960.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-13960 (NULL bytes in XPath query)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$domd = new DOMDocument();
8+
@$domd->loadHTML("<foo>tes\x00t</foo>");
9+
$xp = new DOMXPath($domd);
10+
try {
11+
$xp->query("//foo[contains(text(), " . $xp->quote("tes\x00t") . ")]");
12+
} catch (ValueError $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
?>
16+
--EXPECT--
17+
DOMXPath::quote(): Argument #1 ($str) must not contain any null bytes

ext/dom/xpath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ PHP_METHOD(DOMXPath, registerPhpFunctionNS)
473473
PHP_METHOD(DOMXPath, quote) {
474474
const char *input;
475475
size_t input_len;
476-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &input, &input_len) == FAILURE) {
476+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &input, &input_len) == FAILURE) {
477477
RETURN_THROWS();
478478
}
479479
if (memchr(input, '\'', input_len) == NULL) {

0 commit comments

Comments
 (0)