Commit graph

601 commits

Author SHA1 Message Date
Niels Dossche
d2514e3969
Simplify SimpleXML code for checking if count() is overridden by a userland class (#18722) 2025-05-31 15:59:14 +02:00
Niels Dossche
efaae93e48
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18597: Heap-buffer-overflow in zend_alloc.c when assigning string with UTF-8 bytes
2025-05-20 21:32:27 +02:00
Niels Dossche
40e667280b
Fix GH-18597: Heap-buffer-overflow in zend_alloc.c when assigning string with UTF-8 bytes
xmlSave() also can flush in some cases. When the encoding is not
available this can fail for short inputs, resulting in an empty string
which is interned but then wrongly tagged by RETURN_NEW_STR.
Fix this by checking the error condition and switching to RETURN_STR for
defense-in-depth.

This issue also exists on 8.3, but does not crash; however, due to the
different API usage internally I cannot easily fix it on 8.3. There it
gives a partial output.

Closes GH-18606.
2025-05-20 21:32:17 +02:00
Niels Dossche
3ba725a556
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:42 +02:00
Niels Dossche
a019fbd970
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:12 +02:00
Niels Dossche
ba0853888d
Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
For dynamic fetches the cache_slot will be NULL, so we have to check for
that when resetting the cache. For zip and xmlreader this couldn't
easily be tested because of a lack of writable properties.

Closes GH-18307.
2025-04-11 23:33:58 +02:00
Niels Dossche
86a67fef48
Fix GH-12231: SimpleXML xpath should warn when returning other return types than node lists
Closes GH-18073.
2025-03-17 19:37:59 +01:00
Niels Dossche
d95b9d6d32
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:41:21 +01:00
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
5d4707e22a
Merge branch 'PHP-8.4'
* PHP-8.4:
  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:52 +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
789627612a Prevent string duplication if QName without prefix is given 2024-12-29 18:18:38 +01:00
Niels Dossche
921e178562 Remove unnecessary casts 2024-12-29 18:18:38 +01:00
Niels Dossche
9cf2d1fc69 Remove outdated comment 2024-12-29 18:18:38 +01:00
Niels Dossche
d8a5cefa63 Use enum instead of 2 bools for access mode in simplexml 2024-12-29 18:18:38 +01:00
Niels Dossche
e5e7a9319a Use zend_hash_lookup in simplexml
Prevents a double lookup.
2024-12-29 18:18:38 +01:00
Niels Dossche
1a61d29d5d Use zend_new_pair 2024-12-29 18:18:38 +01:00
Niels Dossche
e21de85b9f Remove pointless conversion from UNDEF to NULL 2024-12-29 18:18:38 +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