Commit graph

266 commits

Author SHA1 Message Date
Niels Dossche
525aeff070
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17500: Segfault with requesting nodeName on nameless doctype
2025-01-17 19:37:14 +01:00
Niels Dossche
82d71a82aa
Fix GH-17500: Segfault with requesting nodeName on nameless doctype
Closes GH-17344.
2025-01-17 19:36:47 +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
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
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
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
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
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
067eb8c0d7
[ci skip] Remove confusing comments
They are readonly / not readonly depending on the class where they're used.
However, the comment makes this confusing [1].

[1] https://github.com/php/php-src/issues/15578#issuecomment-2310389300
2024-08-27 22:24:39 +02:00
Niels Dossche
2cfcfe09a0
Convert more common methods in dom/node.c to fast ZPP (#15043) 2024-07-20 20:20:32 +02:00
Niels Dossche
80a4783d25
Deduplicate NULL checks in ext/dom (#15015)
This introduces a new helper php_dom_create_nullable_object() that does
the NULL check and puts NULL in return_value. Otherwise it runs
php_dom_create_object(). This deduplicates a bit of code.
2024-07-18 21:20:03 +02:00
Niels Dossche
6980eba863
Support templated content
The template element in HTML 5 is special in the sense that it does not
add its contents into the DOM tree, but instead keeps them in a separate
shadow DOM document fragment. Interacting with the DOM tree cannot touch
the elements in the document fragment.

Closes GH-14906.
2024-07-15 11:10:51 +02:00
Niels Dossche
4ef7539144
Split off private data from the ns mapper 2024-07-15 11:02:52 +02:00
Niels Dossche
768900b180 Implement Dom $innerHTML property 2024-07-02 11:15:38 -07:00
Niels Dossche
c66221b7ba
Fix arginfo violation in removeChild() (#14717)
It was possible to return false without throwing an exception.
This is even wrong in "old DOM" because we expect either a NOT_FOUND_ERR
or NO_MODIFICATION_ALLOWED_ERR according to the documentation.
A side effect of this patch is that it prioritises NOT_FOUND_ERR over
NO_MODIFICATION_ALLOWED_ERR but I think that's fine.
2024-06-29 16:32:36 +02:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Niels Dossche
8dc2391bae
Fix bug #79701: getElementById does not correctly work with duplicate definitions
This is a long standing bug: IDs aren't properly tracked causing either
outdated or plain incorrect results from getElementById.

This PR implements a pragmatic solution in which we still try to use the
ID lookup table to a degree, but only as a performance boost not as a
"single source of truth". Full details are explained in the
getElementById code.

Closes GH-14349.
2024-06-01 12:55:05 +02:00
Niels Dossche
eeae9875f8 Avoid narrowing 2024-05-13 19:46:51 +02:00
Niels Dossche
1d573000d5 Remove unused arguments 2024-05-13 19:46:51 +02:00
Niels Dossche
e7af2bfd5b Get rid of reserved name usage 2024-05-13 19:46:51 +02:00
Niels Dossche
de4c9c3398
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix missing deref in C14N (#14203)
2024-05-11 17:13:20 +02:00
Niels Dossche
59f16223ae
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix missing deref in C14N (#14203)
2024-05-11 17:13:12 +02:00
Niels Dossche
1890d47c51
Fix missing deref in C14N (#14203)
Follow-up for 30a0b0359e, which didn't fix
all places. This is the last remaining place.
2024-05-11 17:12:20 +02:00
Niels Dossche
6e7adb3c48
Update ext/dom names after policy change (#14171) 2024-05-09 10:40:53 +02:00
Niels Dossche
6f989cdb75
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix crash when calling childNodes next() when iterator is exhausted
  Fix references not handled correctly in C14N
  Fix crashes when entity declaration is removed while still having entity references
2024-04-30 22:53:48 +02:00
Niels Dossche
461d890f0a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix crash when calling childNodes next() when iterator is exhausted
  Fix references not handled correctly in C14N
  Fix crashes when entity declaration is removed while still having entity references
2024-04-30 22:38:32 +02:00
Niels Dossche
30a0b0359e
Fix references not handled correctly in C14N
Closes GH-14090.
2024-04-30 22:30:28 +02:00
Niels Dossche
d24a04bba8
Use fast ZPP in very commonly used DOM functions (#14077)
Start using fast ZPP in very commonly used DOM functions, and also try
to unify some branches by using RETURN_BOOL where appropriate.
2024-04-30 17:29:33 +02:00
Niels Dossche
3626e2d552
Get rid of remaining usages of zval_try_get_string() (#14041)
This isn't necessary because the cases where we use it will always
succeed because the properties always have the type string|null.
2024-04-24 23:47:10 +02:00
Niels Dossche
539d8d9259 Use common helper macro for getting the node in property handlers 2024-03-10 11:08:46 +01:00
Niels Dossche
649394d357 Remove redundant namespace define 2024-03-10 11:08:46 +01:00
Niels Dossche
d57e7a920b Use BAD_CAST consistently 2024-03-10 11:08:46 +01:00
Niels Dossche
6c55513e33 Use true instead of 1 with php_dom_throw_error 2024-03-10 11:08:46 +01:00
Niels Dossche
751163d18e Change stricterror type to bool 2024-03-10 11:08:46 +01:00
Niels Dossche
63bb04e5bf Simplify DOM_RET_OBJ macro 2024-03-10 11:08:46 +01:00