Commit graph

585 commits

Author SHA1 Message Date
Niels Dossche
ee4a9a4a7c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:37:07 +01:00
Niels Dossche
ce8ab5f16a
Fix GH-17736: Assertion failure zend_reference_destroy()
The cache slot for FETCH_OBJ_W in function `test` is primed with the
class for C. The next call uses a simplexml instance and reuses the same
cache slot. simplexml's get_property_ptr handler does not use the cache
slot, so the old values remain in the cache slot. When
`zend_handle_fetch_obj_flags` is called this is not guarded by a check
for the class entry. So we end up using the prop_info from the property
C::$a instead of the simplexml property.

This patch adds a reset to the cache slots in the property address fetch
code and also in the extensions with a non-standard reference handler.
This keeps the run time cache consistent and avoids the issue without
complicating the fast paths.

Closes GH-17739.
2025-03-02 22:33:32 +01:00
Niels Dossche
3eb79e146f
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17409: Assertion failure Zend/zend_hash.c:1730
  NEWS
  Add comment
  Fix GH-16892: ini_parse_quantity() fails to parse inputs starting with 0x0b
  Fix GH-16886: ini_parse_quantity() fails to emit warning for 0x+0
  Merge duplicate code blocks
2025-01-09 19:54:46 +01:00
Niels Dossche
a2a7287b87
Fix GH-17409: Assertion failure Zend/zend_hash.c:1730
The array merging function may still hold the properties array while the
object is already being destroyed. Therefore, we should take into
account the refcount in simplexml's destruction code.
It may be possible to trigger this in other ways too.

Closes GH-17421.
2025-01-09 19:53:54 +01:00
Niels Dossche
9eaee687d3
Revert 746b1cf4 "Access long value directly for call to count() in simplexml"
The count() function has a tentative return type.
Add a comment for the future.
2024-12-29 14:37:25 +01:00
Niels Dossche
aea64c89f2
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17153: SimpleXML crash when using autovivification on document
2024-12-15 11:32:02 +01:00
Niels Dossche
a57a434f95
Fix GH-17153: SimpleXML crash when using autovivification on document
In the case of a member string, `mynode` may also be a document, which
doesn't have a namespace.

Closes GH-17156.
2024-12-15 11:31:32 +01:00
Niels Dossche
953f4ef2cb
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17040: SimpleXML's unset can break DOM objects
2024-12-06 20:10:03 +01:00
Niels Dossche
7acc3ac808
Fix GH-17040: SimpleXML's unset can break DOM objects
Don't free the underlying nodes if we still have objects pointing to
them, otherwise the objects are left with a NULL node pointer.

Closes GH-17046.
2024-12-06 20:06:51 +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
2ba18590bf
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16808: Segmentation fault in RecursiveIteratorIterator->current() with a xml element input
2024-11-16 13:41:29 +01:00
Niels Dossche
fbb0061993
Fix GH-16808: Segmentation fault in RecursiveIteratorIterator->current() with a xml element input
When the current data is invalid, NULL must be returned. At least that's
how the check in SPL works and how other extensions do this as well.
If we don't do this, an UNDEF value gets propagated to a return value
(misprinted as null); leading to issues.

Closes GH-16825.
2024-11-16 13:39:46 +01:00
Niels Dossche
0d9b039568
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15837: Segmentation fault in ext/simplexml/simplexml.c
2024-09-11 20:40:01 +02:00
Niels Dossche
bc20b403cf
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15837: Segmentation fault in ext/simplexml/simplexml.c
2024-09-11 20:39:30 +02:00
Niels Dossche
b5834c12d4
Fix GH-15837: Segmentation fault in ext/simplexml/simplexml.c
We should check if the iterator data is still valid, because if it
isn't, then the type info is UNDEF, but the pointer value may be
dangling.

Closes GH-15841.
2024-09-11 20:38:38 +02:00
Niels Dossche
51d93c1947 Remove failure paths for infallible code in simplexml
For IS_STRING, sxe_object_cast_ex() will call cast_object() which cannot
fail for IS_STRING.
2024-08-28 18:02:31 +02:00
Niels Dossche
9979f4748c Remove unused parameter from match_ns() 2024-08-28 18:02:31 +02:00
Niels Dossche
2fe8dd1054 Remove unused parameter of php_sxe_reset_iterator() 2024-08-28 18:02:31 +02:00
Niels Dossche
7f37c22d22 Cleanup php_sxe_count_elements_helper() 2024-08-28 18:02:31 +02:00
Niels Dossche
9b73d591c6
Avoid string duplication if possible in SimpleXMLElement::addAttribute() (#15606) 2024-08-27 23:07:20 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
e7c4d54d65 Use new helper function for "cannot be empty" ValueErrors 2024-08-21 21:12:17 +01:00
Niels Dossche
746b1cf43e
Access long value directly for call to count() in simplexml (#15278)
Because the signature is checked at compile time, we know that the only
possible return value (if there is no exception) is IS_LONG. So we can
avoid some work.
2024-08-08 19:28:03 +02:00
Niels Dossche
cf14adf897
Avoid string duplications in simplexml (#15122)
Switch to zend_string which allows us to use zend_string_copy.
2024-07-27 16:21:07 +02:00
Niels Dossche
477c2afb48 Fix typo in simplexml.c 2024-07-06 14:58:50 -07:00
Niels Dossche
acda7ed5c3 Stop using reserved names in simplexml 2024-07-06 14:58:50 -07:00
David Carlier
66a06d6fa5
Merge branch 'PHP-8.3' 2024-07-01 22:38:05 +01:00
David Carlier
20866b37aa
Merge branch 'PHP-8.2' into PHP-8.3 2024-07-01 22:37:54 +01:00
David Carlier
2edf12e87f
Fix GH-14638: null dereference after XML parsing failure.
object document is null if the parsing had failed prior to cast to
string.
2024-07-01 22:36:32 +01: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
Gina Peter Banyard
fd2d869642
Clean-up some more headers (#14416)
Remove unused headers (such as php_ini.h for extensions that don't define INI settings)
Use more specific headers when possible
2024-06-08 17:15:36 +01:00
Niels Dossche
dfde0d4cef Handle dumping node to file 2024-05-11 18:09:39 +02:00
Niels Dossche
0c490ade0d Handle dumping document to file 2024-05-11 18:09:39 +02:00
Niels Dossche
44485892df Factor out all common code for XML serialization and merge common paths 2024-05-11 18:09:39 +02:00
Niels Dossche
8637a3f5b0 Fix getDocNamespaces() not working when only having xmlns attributes without an internal declaration in the document 2024-05-05 10:14:40 +02:00
Niels Dossche
4bd63568fb
Fix argument type of simplexml_import_dom (#13170)
It needs to be "object".
This is because first- and third-party extension can register custom
node types using `php_libxml_register_export`. So we don't know upfront
what types can be expected.

This also changes the error to a TypeError everywhere.
2024-01-18 20:28:01 +01:00
David CARLIER
9726721560
general signatures discrepencies fixes (#13122) 2024-01-10 22:19:23 +00:00
Niels Dossche
61b7370b6d Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12929: SimpleXMLElement with stream_wrapper_register can segfault
  Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
  Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2023-12-17 11:52:48 +01:00
Niels Dossche
f75931ad9e Fix GH-12929: SimpleXMLElement with stream_wrapper_register can segfault
Move SimpleXML invalidation code after node checks

This is safe, i.e. the tree hasn't been modified yet, because either we
didn't call a libxml modification function yet, or xmlNewChild is called
with a NULL pointer, which makes it bail out and return NULL.

Closes GH-12947.
2023-12-17 11:51:42 +01:00
Niels Dossche
4fc336c784 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
  Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2023-12-17 11:50:42 +01:00
Niels Dossche
abf4c116b1 Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
Closes GH-12945.
2023-12-17 11:47:11 +01:00
Niels Dossche
ec2ef6465d Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Apply SimpleXML iterator fixes only on master
2023-09-30 17:55:34 +02:00
Niels Dossche
77f44b2281 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Apply SimpleXML iterator fixes only on master
2023-09-30 17:53:57 +02:00
Niels Dossche
b842ea4fa8 Apply SimpleXML iterator fixes only on master
Many methods in SimpleXML reset the iterator when called. This has the
consequence that mixing these operations with loops can cause infinite
loops, or the loss of iteration data.
Some people may however rely on the resetting behaviour. To prevent
unintended breaks in stable branches, let's only apply the fix to master.

This reverts GH-12193, GH-12229, GG-12247 for stable branches while
keeping them on master, adding a note in UPGRADING as well.
2023-09-30 17:48:05 +02:00
Niels Dossche
2e8cdd8eec Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
2023-09-25 19:50:58 +02:00
Niels Dossche
190a535325 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
2023-09-25 19:49:36 +02:00
Niels Dossche
9c37a02c54 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
2023-09-25 19:48:49 +02:00
Niels Dossche
82a84d0b7b Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
Closes GH-12289.
2023-09-25 19:47:09 +02:00
Niels Dossche
aab6bbc6f5 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (<= PHP 8.3)
  Fix bug #55098: SimpleXML iteration produces infinite loop
2023-09-20 21:02:36 +02:00
Niels Dossche
b08802d160 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (<= PHP 8.3)
  Fix bug #55098: SimpleXML iteration produces infinite loop
2023-09-20 20:59:22 +02:00