1
0
mirror of https://github.com/php/php-src.git synced 2026-03-30 12:13:02 +02:00
Commit Graph

1564 Commits

Author SHA1 Message Date
Niels Dossche
d7a37cc9ad Add missing backslash for TokenList interfaces in stub (#17009)
Discovered while trying to generate class synopses.
2024-12-01 15:18:44 +01:00
Niels Dossche
52c7c74ebb Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16906: Reloading document can cause UAF in iterator
2024-11-24 18:20:21 +01:00
Niels Dossche
9d39ff764e Fix GH-16906: Reloading document can cause UAF in iterator
Closes GH-16909.
2024-11-24 18:19:45 +01:00
Niels Dossche
d3fada3748 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16777: Calling the constructor again on a DOM object after it is in a document causes UAF
  Fix GH-16808: Segmentation fault in RecursiveIteratorIterator->current() with a xml element input
2024-11-16 13:42:14 +01:00
Niels Dossche
18b18f0ee0 Fix GH-16777: Calling the constructor again on a DOM object after it is in a document causes UAF
Closes GH-16824.
2024-11-16 13:42:01 +01:00
Niels Dossche
d5e6dd8f2b Add missing cache invalidation for innerHTML (#16652)
* Add test with wrong output

* Add missing cache invalidation for innerHTML
2024-10-30 22:14:20 +01:00
Niels Dossche
65fbf47472 Fix static analysis warning
The condition is already checked at the start of the function, mark this
code properly as unreachable.
2024-10-30 20:55:50 +01:00
Niels Dossche
6e82ae9990 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16595: Another UAF in DOM -> cloneNode
  Fix GH-16593: Assertion failure in DOM->replaceChild
2024-10-28 19:45:22 +01:00
Niels Dossche
ed21ebd8aa Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16595: Another UAF in DOM -> cloneNode
  Fix GH-16593: Assertion failure in DOM->replaceChild
2024-10-28 19:39:24 +01:00
Niels Dossche
9d8983c061 Fix GH-16595: Another UAF in DOM -> cloneNode
We need to perform all sanity checks before doing any modification.
I don't have a reliable and easy test for this on 8.2, but I have one
for 8.4.

Closes GH-16598.
2024-10-28 19:37:08 +01:00
Niels Dossche
d89dd28d3b Fix GH-16593: Assertion failure in DOM->replaceChild
This is already forbidden by libxml, but this condition isn't properly
checked; so the return value and lack of error makes it seem like it
worked while it actually didn't. Furthermore, this can break assumptions
and assertions later on.

Closes GH-16596.
2024-10-28 19:36:29 +01:00
Niels Dossche
947e319b76 Fix GH-16594: Assertion failure in DOM -> before
The invalid parent condition can actually happen because PHP's DOM is
allows to get children of e.g. attributes; something normally not
possible.

Closes GH-16597.
2024-10-28 19:32:20 +01:00
Christoph M. Becker
30dd291628 Updates for libxml2 >= 2.13.0
libxml2 2.13.0 introduced some relevant changes regarding the treatment
of file paths on Windows[1].  Thus we un-xfail bug69753.phpt and its
companion, and we adjust dom004.phpt.  And we also disable the
workaround for erroneous file:/ URIs on Windows.

[1] <8ab1b122c4>

Closes GH-16536.
2024-10-22 00:17:12 +02:00
Niels Dossche
a0266920e4 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16535: UAF when using document as a child
  Fix GH-16533: Segfault when adding attribute to parent that is not an element
2024-10-21 20:57:42 +02:00
Niels Dossche
5a09e0105e Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16535: UAF when using document as a child
  Fix GH-16533: Segfault when adding attribute to parent that is not an element
2024-10-21 20:57:22 +02:00
Niels Dossche
51b642f2c9 Fix GH-16535: UAF when using document as a child
Documents can never be children of any node.

Closes GH-16539.
2024-10-21 20:56:14 +02:00
Niels Dossche
a0a7361b64 Fix GH-16533: Segfault when adding attribute to parent that is not an element
Attributes are only valid as children of elements. This bug goes back
all the way.

Closes GH-16537.
2024-10-21 20:55:42 +02:00
Niels Dossche
55266d420b Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16473: dom_import_simplexml stub is wrong
2024-10-17 23:28:34 +02:00
Niels Dossche
c26d5f20e8 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16473: dom_import_simplexml stub is wrong
2024-10-17 23:27:23 +02:00
Niels Dossche
41af9335b7 Fix GH-16473: dom_import_simplexml stub is wrong
It's been wrong since PHP 8.0 at least, and the signature was inherited
in 8.4-dev to the new DOM methods.

Closes GH-16489.
2024-10-17 23:26:50 +02:00
Niels Dossche
81a2cd4dac Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix various document ref pointer mismanagements
2024-10-17 21:21:49 +02:00
Niels Dossche
5cb38e9d24 Fix various document ref pointer mismanagements
- Properly handle attributes
- Fix potential NULL dereference if the intern document pointer is NULL

Fixes GH-16336.
Fixes GH-16338.
Closes GH-16345.
2024-10-17 21:18:50 +02:00
Niels Dossche
d70f3ba9a5 Fix GH-16465: Heap buffer overflow in DOMNode->getElementByTagName
If the input contains NUL bytes then the length doesn't match the actual
duplicated string's length. Note that libxml can't handle this properly
anyway so we just reject NUL bytes and too long strings.

Closes GH-16467.
2024-10-16 22:55:18 +02:00
Niels Dossche
b7b0b954be Restore accidentally deleted check 2024-10-12 13:41:24 +02:00
Niels Dossche
c31eac7284 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add missing hierarchy checks to replaceChild
  Fix GH-16337: Use-after-free in SplHeap
2024-10-12 13:39:06 +02:00
Niels Dossche
3ed01d454d Add missing hierarchy checks to replaceChild
You can break the hierarchy for attribute nodes, use the helper function
introduced recently [1] to fix this issue.

[1] 066d18f2

Closes GH-16377.
2024-10-12 13:32:13 +02:00
Niels Dossche
25d0661d21 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16316: DOMXPath breaks when not initialized properly
2024-10-10 19:29:16 +02:00
Niels Dossche
5ae792715e Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16316: DOMXPath breaks when not initialized properly
2024-10-10 19:28:53 +02:00
Niels Dossche
1d0fbdf449 Fix GH-16316: DOMXPath breaks when not initialized properly
Closes GH-16330.
2024-10-10 19:28:20 +02:00
Niels Dossche
1f84f5c27a Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16292: Segmentation fault in ext/xmlreader/php_xmlreader.c:1282
2024-10-08 20:58:20 +02:00
Niels Dossche
54eab7b3cf Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16292: Segmentation fault in ext/xmlreader/php_xmlreader.c:1282
2024-10-08 20:57:54 +02:00
Niels Dossche
5c1249391b Fix GH-16292: Segmentation fault in ext/xmlreader/php_xmlreader.c:1282
3 issues:
1) RETURN_NULL() was used via the macro NODE_GET_OBJ(), but the function
   returns false on failure and cannot return null according to its
   stub.
2) The struct layout of the different implementors of libxml only
   guarantees overlap between the node pointer and the document
   reference, so accessing the std zend_object may not work.
3) DOC_GET_OBJ() wasn't using ZSTR_VAL().

Closes GH-16307.
2024-10-08 20:54:07 +02:00
Niels Dossche
98e5308488 Update Lexbor (#16288)
Sync up to lexbor/lexbor@72236d31da.
Reason: pulling in mainly
lexbor/lexbor@cbf1263e78 for the WHATWG
encoding update.
2024-10-08 19:15:45 +02:00
Niels Dossche
1e949d189a Fix edge-case in DOM parsing decoding
There are three connected subtle issues:
1) The fast path didn't correctly handle the case where the decoder
   requests more data. This caused a bogus additional replacement
   sequence to be outputted when encountering an incomplete sequence at
   the edges of a buffer.
2) The finishing of decoding incorrectly assumed that the fast path
   cannot be in a state where the last few bytes were an incomplete
   sequence, but this is not true as shown by test 08.
3) The finishing of decoding could output bytes twice because it called
   into dom_process_parse_chunk() twice without clearing the decoded
   data. However, calling twice is not even necessary as the entire
   buffer cannot be filled up entirely.

Closes GH-16226.
2024-10-05 18:27:18 +02:00
Niels Dossche
ba0834bc2c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix bugs GH-16150 and GH-16152: intern document mismanagement
2024-10-03 19:33:09 +02:00
Niels Dossche
d4a4d2e7a9 Fix bugs GH-16150 and GH-16152: intern document mismanagement
The reference counts of the internal document pointer are mismanaged.
In the case of fragments the refcount may be increased too much, while
for other cases the document reference may not be applied to all
children.

This bug existed for a long time and this doesn't reproduce (easily)
on 8.2 due to other bugs. Furthermore 8.2 will enter security mode soon,
and this change may be too risky.

Fixes GH-16150.
Fixed GH-16152.
Closes GH-16178.
2024-10-03 19:28:50 +02:00
Niels Dossche
3be6ff66b8 Fix GH-16190: Using reflection to call Dom\Node::__construct causes assertion failure
Closes GH-16193.
2024-10-03 19:25:58 +02:00
Niels Dossche
341c26fc3f Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
2024-10-01 21:47:52 +02:00
Niels Dossche
cd67c090a9 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
2024-10-01 21:47:26 +02:00
Niels Dossche
066d18f2e8 Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
Unfortunately, old DOM allows attributes to be used as parent nodes.
Only text nodes and entities are allowed as children for these types of
nodes, because that's the constraint DOM and libxml give us.

Closes GH-16156.
2024-10-01 21:46:12 +02:00
Niels Dossche
853322faab Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16149: Null pointer dereference in DOMElement->getAttributeNames()
2024-10-01 21:03:31 +02:00
Niels Dossche
63e1ebe78d Fix GH-16149: Null pointer dereference in DOMElement->getAttributeNames()
A namespace without a prefix is by definition always the "xmlns"
namespace.

Closes GH-16155.
2024-10-01 21:02:23 +02:00
Niels Dossche
97546746d0 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16039: Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c
2024-09-25 19:39:49 +02:00
Niels Dossche
68d494d690 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16039: Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c
2024-09-25 19:33:29 +02:00
Niels Dossche
043b9e1f13 Fix GH-16039: Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c
dom_object_get_node() can fail if we don't have a user object
associated.

Closes GH-16056.
2024-09-25 19:31:19 +02:00
Niels Dossche
cf0a44a38a [ci skip] Fix typo 2024-09-23 22:19:15 +02:00
Niels Dossche
90f81ca7cb [ci skip] Exchange TODO comment for an explanation
Such that nobody actually attempts to implement this.
2024-09-23 21:10:14 +02:00
Niels Dossche
7e6e71255e Small optimization in dom_local_name_compare_ex() (#15950)
We can use `memcmp()` directly and skip some of the logic handling
in `zend_binary_strcmp()`. `perf record` shows a reduction for
`dom_html5_serializes_as_void()` from 3.12% to 0.77%.
2024-09-20 08:11:13 +02:00
Niels Dossche
7bf5b7fa78 Use cache slot for dom_property_exists() (#15941) 2024-09-18 17:23:24 +02:00
Niels Dossche
c9a4abadcc Fix unsetting DOM properties
This never did anything in lower versions, but on master this crashes
because the virtual properties don't have backing storage. Just forbid
it since it was useless to begin with.

Closes GH-15891.
2024-09-17 19:24:49 +02:00