[php-src] master: Make (DOM)XPath::quote only accept strings without NULL bytes (#13960)
| From: | Niels Dossche via GitHub | Date: | Sun, 14 Apr 2024 19:16:13 +0000 |
| Subject: | [php-src] master: Make (DOM)XPath::quote only accept strings without NULL bytes (#13960) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-128105@lists.php.net to get a copy of this message | ||
Author: Niels Dossche (nielsdos)
Committer: GitHub (web-flow)
Pusher: nielsdos
Date: 2024-04-14T21:16:07+02:00
Commit: https://github.com/php/php-src/commit/a136117eaa856cc34d921dffb8b3a9163bd986f4
Raw diff: https://github.com/php/php-src/commit/a136117eaa856cc34d921dffb8b3a9163bd986f4.diff
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>
Changed paths:
A ext/dom/tests/gh13960.phpt
M ext/dom/xpath.c
Diff:
diff --git a/ext/dom/tests/gh13960.phpt b/ext/dom/tests/gh13960.phpt
new file mode 100644
index 000000000000..fae628f49c07
--- /dev/null
+++ b/ext/dom/tests/gh13960.phpt
@@ -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
diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c
index 82926d43a29f..8919559373e2 100644
--- a/ext/dom/xpath.c
+++ b/ext/dom/xpath.c
@@ -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) {