Commit graph

315 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
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
Máté Kocsis
f4f2fe51cd
Fix property_exists() and unset() for XMLReader (#16079) 2024-09-28 21:08:47 +02:00
Peter Kokot
888eb370cf
Fix -Wundef/C4668 warnings (#15853)
- ZTS is either undefined or defined (to 1)
- PHP_WIN32 is either undefined or defined (to 1)
- HAVE_LIBEDIT is either undefined or defined (to 1)
2024-09-14 11:28:32 +02:00
Bob Weinand
25d761623c
Make internal run_time_cache a persistent allocation (#15040)
We also add zend_map_ptr_static, so that we do not incur the overhead of constantly recreating the internal run_time_cache pointers on each request.
This mechanism might be extended for mutable_data of internal classes too.
2024-09-07 01:45:26 +02:00
Niels Dossche
6c63c48a7e Use virtual annotation in XMLReader
All properties of XMLReader are virtual and therefore don't need backing
storage.
2024-08-26 21:17:49 +02:00
Máté Kocsis
8d12f666ae
Fix registration of internal readonly child classes (#15459)
Currently, internal classes are registered with the following code:

INIT_CLASS_ENTRY(ce, "InternalClass", class_InternalClass_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ...;

This has worked well so far, except if InternalClass is readonly. It is because some inheritance checks are run by zend_register_internal_class_ex before ZEND_ACC_READONLY_CLASS is added to ce_flags.

The issue is fixed by adding a zend_register_internal_class_with_flags() zend API function that stubs can use from now on. This function makes sure to add the flags before running any checks. Since the new API is not available in lower PHP versions, gen_stub.php has to keep support for the existing API for PHP 8.3 and below.
2024-08-24 12:36:54 +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
Peter Kokot
f66feaec0f
Sync HAVE_<extension> help texts (#15167)
This syncs all help texts of extension preprocessor macros to the same
style "Define to 1 if the PHP extension '<ext>' is available.".
[skip ci]
2024-08-02 01:41:47 +02:00
Niels Dossche
e0a2e2e59c
Fix GH-15123: var_dump doesn't actually work on XMLReader (#15130) 2024-07-28 19:36:07 +02:00
Peter Kokot
32210ce967
Autotools: Sync CS in XML related extensions (#15110)
- PHP_SETUP_LIBXML arguments quoted
- Help texts updated for HAVE_LIBXML, HAVE_DOM, HAVE_XMLREADER,
  HAVE_XMLWRITER, HAVE_SOAP, HAVE_SIMPLEXML, and HAVE_XML CPP macros
- Duplicate HAVE_LIBXML symbol definition in PHP_SETUP_LIBXML M4 macro
  removed (the HAVE_LIBXML marks that PHP libxml extension is available and
  not only that libxml2 library is available)
2024-07-27 22:48:51 +02:00
Ilija Tovilo
a26ec58fa1
De-duplicate readonly property modification error message (#14972) 2024-07-16 16:29:40 +02:00
Peter Kokot
bee84c0468
Autotools: Quote PHP_SUBST arguments in extensions (#14748) 2024-07-02 06:56:18 +02:00
Niels Dossche
4cab7f90a1 [RFC] Implement XMLReader::fromUri() and XMLReader::fromString() 2024-06-29 09:04:35 -07:00
Niels Dossche
acf2762857 [RFC] Add stream open functions to XML{Reader,Writer}
RFC: https://wiki.php.net/rfc/xmlreader_writer_streams
2024-06-29 09:04:35 -07: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
Peter Kokot
dd4e2ef5b0
Update ext/xmlreader dependencies (#14572)
- ext/dom is optional (using HAVE_DOM for cases when dom is build as
  a shared extension to make it required in that case)
- ext/libxml is required
2024-06-15 16:25:26 +02:00
Niels Dossche
d934840f44
Fix deprecation warning 2024-05-10 16:26:44 +02:00
Niels Dossche
94479fefe5
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14183: XMLReader::open() can't be overridden
2024-05-10 15:58:48 +02:00
Niels Dossche
d2970cc81f
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14183: XMLReader::open() can't be overridden
2024-05-10 15:58:14 +02:00
Niels Dossche
15813d69a5
Fix GH-14183: XMLReader::open() can't be overridden
We should only return the override if the internal static method is matched.

Closes GH-14194.
2024-05-10 15:57:09 +02:00
Niels Dossche
b3700e29cc
Simplify prop handler of XMLReader (#14023)
As XMLReader only exposes a single class, and the property handlers are
statically set, we don't need to store the pointer to the property
handler table inside the object.
This simplifies the code and reduces the memory required for XMLReader.
2024-04-20 23:22:38 +02:00
Máté Kocsis
b06c95b631
Declare the missing true return types (#13709) 2024-03-16 07:26:37 +01:00
Niels Dossche
63bb04e5bf Simplify DOM_RET_OBJ macro 2024-03-10 11:08:46 +01:00
Ayesh Karunaratne
353d4ce075
ext/xmlreader: Add class constant types to stub (#13596)
Declares class constant types for the `XMLReader` class.
2024-03-05 20:50:54 +01:00
Niels Dossche
6d721b21a1 Use string literal equality helper function in xmlreader_get_method 2024-02-25 16:25:52 +01:00
Niels Dossche
da1a9402f8 Set xmlreader property handler hash size to a precalculated value 2024-02-25 16:25:52 +01:00
Niels Dossche
7f080d3584 Don't put xmlreader prop handler data on the heap 2024-02-25 16:25:52 +01:00
Niels Dossche
06a89a9159 Make readonly error message consistent 2024-02-25 16:25:52 +01:00
Niels Dossche
b68b55be8f Remove unused write_func in php_xmlreader.c 2024-02-25 16:25:52 +01:00
Niels Dossche
586adf964f Remove unimplemented, unreferenced function from php_xmlreader.c 2024-02-25 16:25:52 +01:00
Máté Kocsis
10957e498c
Do not generate frameless info items when func info generation is disabled
While here, I fixed newlines around arginfo and function entry generation. Previously, newlines were repeated.
2024-02-18 11:39:00 +01:00
Peter Kokot
8d5fc8d23f Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Use EXTENSIONS instead of SKIPIF sections in *.phpt
2024-01-31 11:20:44 +01:00
Peter Kokot
218a93b898 Use EXTENSIONS instead of SKIPIF sections in *.phpt
This also fixes skipped tests due to different naming "zend-test"
instead of "zend_test" and "PDO" instead of "pdo":

- ext/dom/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/simplexml/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/xmlreader/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/zend_test/tests/observer_sqlite_create_function.phpt

EXTENSIONS section is used for the Windows build to load the non-static
extensions.

Closes GH-13276
2024-01-31 11:18:21 +01:00
Niels Dossche
a64b48ba92 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  Fix null pointer dereferences in case of allocation failure
2023-10-24 19:42:43 +02:00
Niels Dossche
dd8a945eb7 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix null pointer dereferences in case of allocation failure
2023-10-24 19:36:57 +02:00
icy17
900f0cab9f Fix null pointer dereferences in case of allocation failure
Closes GH-12506.
2023-10-24 19:34:47 +02:00
Ben Ramsey
3d5f239474
Merge branch 'PHP-8.2' 2023-07-31 20:15:51 -05:00
Ben Ramsey
7ecb284926
Merge branch 'PHP-8.1' into PHP-8.2 2023-07-31 20:06:37 -05:00
Ben Ramsey
ebbccb3dc6
Merge branch 'PHP-8.0' into PHP-8.1 2023-07-31 20:01:03 -05:00
Niels Dossche
62228a2568
Disable global state test on Windows
It looks like the config.w32 uses CHECK_HEADER_ADD_INCLUDE to add the include
path to libxml into the search path.
That doesn't happen in zend-test.
To add to the Windows trouble, libxml is statically linked in, ext/libxml can
only be built statically but ext/zend-test can be built both statically and
dynamically.
So the regression tests won't work in all possible configurations anyway on Windows.
All of this is no problem on Linux because it just uses dynamic linking
and pkg-config, without any magic.

Signed-off-by: Ben Ramsey <ramsey@php.net>
2023-07-31 19:55:10 -05:00
Derick Rethans
86afbe10e2 Merge branch 'PHP-8.2' 2023-07-31 19:57:02 +01:00
Derick Rethans
deddf4692a Merge branch 'PHP-8.1' into PHP-8.2 2023-07-31 19:54:44 +01:00
Derick Rethans
0870ebb862 Merge branch 'PHP-8.0' into PHP-8.1 2023-07-31 19:53:43 +01:00
Niels Dossche
c283c3ab0b Sanitize libxml2 globals before parsing
Fixes GHSA-3qrf-m4j2-pcrr.

To parse a document with libxml2, you first need to create a parsing context.
The parsing context contains parsing options (e.g. XML_NOENT to substitute
entities) that the application (in this case PHP) can set.
Unfortunately, libxml2 also supports providing default set options.
For example, if you call xmlSubstituteEntitiesDefault(1) then the XML_NOENT
option will be added to the parsing options every time you create a parsing
context **even if the application never requested XML_NOENT**.

Third party extensions can override these globals, in particular the
substitute entity global. This causes entity substitution to be
unexpectedly active.

Fix it by setting the parsing options to a sane known value.
For API calls that depend on global state we introduce
PHP_LIBXML_SANITIZE_GLOBALS() and PHP_LIBXML_RESTORE_GLOBALS().
For other APIs that work directly with a context we introduce
php_libxml_sanitize_parse_ctxt_options().
2023-07-31 19:47:19 +01:00
Ilija Tovilo
7b355e8d34
Revert "Merge branch 'PHP-8.2'"
This reverts commit 45a3f178dc, reversing
changes made to b2a54bc6af.
2023-07-04 09:18:49 +02:00