1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Commit Graph

939 Commits

Author SHA1 Message Date
Niels Dossche
0b231c4895 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
2025-10-12 11:25:31 +02:00
Niels Dossche
aa1585f110 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
2025-10-12 11:25:25 +02:00
Niels Dossche
efa1fafc2f Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
If only we did not have the pseudo-key "@attributes", we could've just
removed the custom get_debug_info implementation and this would work out
of the box. Anyway, we just have to manually check for an override now.

Closes GH-20131.
2025-10-12 11:24:45 +02:00
Niels Dossche
c1a6627417 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix NEWS order
  Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
2025-09-29 16:08:56 +02:00
Niels Dossche
1bda46eb83 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix NEWS order
  Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
2025-09-29 16:08:31 +02:00
Niels Dossche
d94846c3b4 Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
Normally, simplexml cannot import document nodes,
but xsl allows to circumvent this.
A document does not have a name, so we return the empty string
in that case.
While we could add an explicit check, we might as well switch
the macro to a form that would be more optimal anyway as many
tag names can be single characters.

The test was added in xsl because adding it in simplexml would
break out-of-tree builds of simplexml.

Closes GH-19990.
2025-09-29 16:07:34 +02:00
Niels Dossche
542712099f Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix naming clash with libxml macro
2025-09-14 16:40:47 +02:00
Ruoyu Zhong
8774e96bd4 Fix naming clash with libxml macro
In the macOS 26 SDK, xmlFree is defined as a macro for free. This causes
issues where a same-named variable is used. Renaming the variable to
should_free resolves the issue.

See:

    $ grep -B4 -A2 -n "#define xmlFree(" "Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.sdk/usr/include/libxml/globals.h"
    261-#if defined(LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS)
    262-#define xmlMalloc(size) malloc(size)
    263-#define xmlMallocAtomic(size) malloc(size)
    264-#define xmlRealloc(ptr, size) realloc((ptr), (size))
    265:#define xmlFree(ptr) free(ptr)
    266-#define xmlMemStrdup(str) strdup(str)
    267-#endif

Fixes:
```
    In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include/libxml/xmlIO.h:117,
                    from /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include/libxml/parser.h:813,
                    from /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/php_dom.h:29,
                    from /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:26:
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c: In function 'dom_compare_value':
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:208:17: error: called object 'free' is not a function or function pointer
      208 |                 xmlFree(attr_value);
          |                 ^~~~~~~
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:204:14: note: declared here
      204 |         bool free;
          |              ^~~~
    make: *** [ext/dom/attr.lo] Error 1
```

Closes GH-19832.

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2025-09-14 16:40:22 +02:00
Gina Peter Banyard
05eda4318d Add missing extension dependencies for tests 2025-09-11 15:10:49 +02:00
Gina Peter Banyard
1e0c8baf05 tree: drop non canonical casts and ZPP tests 2025-08-06 13:20:28 +01:00
Gina Peter Banyard
4baecc1d4a ext/simplexml: Remove bool type coercions in tests 2025-06-23 14:57:05 +02:00
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
fd7ebd4d15 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix sxe test
2025-04-11 23:57:03 +02:00
Niels Dossche
7415dc4649 Fix sxe test 2025-04-11 23:56:57 +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
9d60dc16b8 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix test GH-16535 for libxml2 2.14
  Fix tests for libxml2 2.14
2025-03-10 20:23:50 +01:00
Niels Dossche
09189026e6 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix test GH-16535 for libxml2 2.14
  Fix tests for libxml2 2.14
2025-03-10 20:23:43 +01:00
Niels Dossche
1befdce0e6 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix test GH-16535 for libxml2 2.14
  Fix tests for libxml2 2.14
2025-03-10 20:23:36 +01:00
Niels Dossche
239b01db7c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix tests for libxml2 2.14
2025-03-10 20:22:27 +01:00
Niels Dossche
f209eb448e Fix tests for libxml2 2.14
See GH-18009.
2025-03-10 20:22:11 +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
bb46b4b799 Backport 4fe82131: Backport libxml2 2.13.2 fixes (#14816)
Backproted from https://github.com/php/php-src/pull/14789
2024-10-12 15:12:40 +02: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