Commit Graph

16435 Commits

Author SHA1 Message Date
Nikita Popov
3b7c8bb973 Fix bug #80126
When performing an unlinked instanceof, we also need to consider
interfaces of parent classes, as they may not have been inherited
yet.
2020-10-06 16:33:14 +02:00
Nikita Popov
6ea870f5fb Fix bug #80184 2020-10-05 15:24:51 +02:00
Nikita Popov
d3cf597328 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix -Wimplicit-function-declaration in configure
2020-10-05 10:48:04 +02:00
Nikita Popov
9ad5381a2f Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix -Wimplicit-function-declaration in configure
2020-10-05 10:46:46 +02:00
Nikita Popov
aa405b7da2 Fix -Wimplicit-function-declaration in configure
As this is an error with xcode 12, see bug #80171.
2020-10-05 10:43:58 +02:00
Nikita Popov
ae77c7b057 Return correct result code for division by zero
Turns out we do need to return FAILURE here on div by zero
exception. Use a three-way return value from div_function_base.

Fixes oss-fuzz #25975.
2020-10-02 12:09:14 +02:00
Nikita Popov
62c6d6952e Add test instantiating all objects
Intended to find issues in opaque object destructors.

Closes GH-6251.
2020-10-01 18:37:24 +02:00
Dmitry Stogov
773f980e00 Backport of a partial fix for bug Bug #76982 (memory leak declaring closure in included file). 2020-10-01 13:18:21 +03:00
Gabriel Caruso
0574c21b50
Prepare for PHP 8.0 RC1 2020-09-30 00:19:10 +02:00
Nikita Popov
25f1c405ff Update ext/standard parameter names
Closes GH-6214.
2020-09-29 16:49:46 +02:00
Máté Kocsis
7aa2d3519b
Zend parameter renames amendment
Closes GH-6228
2020-09-29 11:04:09 +02:00
Larry Garfield
ea03cbebbc Update PDO parameters for named arguments.
Closes GH-6220
2020-09-28 23:02:05 +01:00
Nikita Popov
36ed9966ce Allow attributes to be applied to property/constant groups
Remove arbitrary restriction that attributes cannot be applied
to property/constant groups.

The attribute applies to all elements of the group, just like
modifiers and types do.

See also https://externals.io/message/111914.

Closes GH-6186.
2020-09-27 11:35:48 +02:00
Nikita Popov
2772751b58 Make constexpr compilation robust against multiple compilation
Instead of setting the old AST type to zero, replace the AST with
the compiled constexpr AST zval. This requires passing in a
zend_ast** instead of a zend_ast*.

This allows compiling ASTs containing constexprs multiple times
-- the second time, the existing compiled representation will be
resused.

This means we no longer need to copy the attributes AST for
promoted properties.
2020-09-27 11:24:22 +02:00
Nikita Popov
5686c16db4 Honor strict_types=1 for attributes, improve backtraces
Make ReflectionAttribute::newInstance() respect the strict_types=1
declaration at the attribute use-site. More generally, pretend that
we are calling the attribute constructor from the place where the
attribute is used, which also means that the attribute location will
show up properly in backtraces and inside "called in" error information.

This requires us to store the attributes strict_types scope (as flags),
as well as the attribute line number. The attribute filename can be
recovered from the symbol it is used on. We might want to expose the
attribute line number via reflection as well.

See also https://externals.io/message/111915.

Closes GH-6201.
2020-09-27 10:42:58 +02:00
Sammy Kaye Powers
e42abeafec
Pass zend_execute_data instead of zend_function to fcall init
The motivation for this change is to prevent extensions from having to check executor globals for the current execute_data during function call init. A previous implementation of the observer API initialized the function call from runtime cache initialization before execute_data was allocated which is why zend_function was passed in.

But now that the observer API is implemented via opcode specialization, it makes sense to pass in the execute_data. This also keeps the API a bit more consistent for existing extensions that already hook zend_execute_ex.

Closes GH-6209
2020-09-25 11:46:15 -07:00
Nikita Popov
450f2ff406 Skip unnecessary unknown() frames
Noticed this while working on attributes strict_types handling.
We sometimes insert dummy frames internally, but I don't think
these should show up in debug_backtrace output unless they're
needed, either to display an include call or to preserve file/line
information that would otherwise get lost.

Closes GH-6195.
2020-09-24 10:34:24 +02:00
Nikita Popov
12d087c346 Use C zpp for get_class_vars() 2020-09-22 13:05:05 +02:00
George Peter Banyard
2ee7e2982f Promote count() warning to TypeError
Closes GH-6180
2020-09-21 21:29:15 +01:00
Nikita Popov
fb4554e431 Throw warning for failed object to int/float conversion
We previously couldn't increase the error level here because it
was coupled to comparison handling. This is no longer the case
in PHP 8.
2020-09-21 17:04:39 +02:00
Nikita Popov
d60c43e397 Convert exception instanceof checks to assertions 2020-09-21 17:04:39 +02:00
Nikita Popov
edf22962ef Make constant redeclaration a warning
We missed the change to make this an Error exception in PHP 8,
but at least elevate it to a warning, to avoid a notice -> exception
jump at a later time.
2020-09-21 17:04:39 +02:00
Christoph M. Becker
3e33e1e86d Check linker compatibility directly from HMODULE
Checking the linker compatibility with extranous `ImageLoad()` calls is
possible, but unnecessary, since the modules are either already loaded
or loaded shortly afterwards, so that we can get the required
information directly from the module handles.  And actually, doing
`ImageLoad()` as well as `LoadLibrary()` leaves a tiny room for a race
condition, because both functions will lookup the module in the search
path, so there is no *guarantee* that both are dealing with the same
module.  Dropping the `ImageLoad()` calls also has the advantage to no
longer face the issue reported in bug #79557.  A very minor additional
advantage is that we no longer have to link against Imagehlp.dll.

Furthermore, there is no need to check for CRT compatibility multiple
times, so we can simplify the signature of `php_win32_crt_compatible`,
and at the same time clean up main.c a bit.

These changes require to change the signature of the exported
`php_win32_image_compatible` and `php_win32_crt_compatible` functions,
which now expect a `HMODULE` and nothing, respectively, instead of the
module name.
2020-09-21 16:25:31 +02:00
Nikita Popov
213b666781 Synchronize GET_CLASS/GET_CALLED_CLASS opcodes with functions
These error conditions throw in the function implementations,
make the opcodes match.
2020-09-21 15:06:04 +02:00
Nikita Popov
d085a7439f Assert on unknown list entry type 2020-09-21 14:58:23 +02:00
Nikita Popov
3642592a12 Remove unnecessary check
We should only produce IS_UNDEF if an exception is thrown, this
check is not needed.
2020-09-21 14:56:14 +02:00
Nikita Popov
8e0789a21c Use proper parameter type in Closure::bindTo() signature 2020-09-21 14:46:10 +02:00
Máté Kocsis
4c821cf206
Improve default value handling of Exception constructors
Closes GH-6166
2020-09-21 12:46:50 +02:00
Nikita Popov
c5f93d191e Fix detection of code outside namespace
Due to improvements to early binding, the opcode based check is
no longer accurate. Reuse the syntactic check we're already using
for declares instead.
2020-09-21 12:37:44 +02:00
Nikita Popov
ef9ab9159b Use assertion for null-termination string
Indicates an implementation bug, make sure we can automatically
detect it.
2020-09-21 12:12:51 +02:00
Nikita Popov
2bf2cede89 Initialize attributes for internal functions
Fixes a crash in Symfony SecurityBundle tests.
2020-09-21 10:50:29 +02:00
Máté Kocsis
64af12d13b
Add support for @implementation-alias in stubs
Closes GH-6170
2020-09-21 10:08:45 +02:00
Máté Kocsis
b15885b522
Separate Closure::bind() implementations
Closure::bind() and Closure::bindTo() are currently reported as aliases in stubs because they have a single implementation. They are not aliases in fact though, they just use zend_parse_method_parameters() cleverly.

Thus, let's separate their implementation so that we don't have to alias Closure::bindTo() anymore. This will also have the advantage that the two ZPP implementations become more clear.

Closes GH-6169
2020-09-19 20:14:22 +02:00
Sammy Kaye Powers
12306728c5
Add system ID entropy API
The `zend_system_id` is a (true global) system ID that fingerprints a process state. When extensions add engine hooks during MINIT/startup, entropy is added the system ID for each hook. This allows extensions to identify that changes have been made to the engine since the last PHP process restart.

Closes GH-5871
2020-09-18 14:26:44 -07:00
Nikita Popov
c5401854fc Run tidy
This should fix most of the remaining issues with tabs and spaces
being mixed in tests.
2020-09-18 14:28:32 +02:00
Dmitry Stogov
d5d31ea3b3 Cleanup observer API and add JIT support 2020-09-18 12:55:58 +03:00
Nikita Popov
34bb5ba2ea Remove support for EXT_NOP
This is an annoying edge case that regularly gets broken. As we're
not aware of significant users of this API, and there are other
ways to hook this, remove support for EXT_NOP.
2020-09-18 11:03:08 +02:00
Sammy Kaye Powers
9e94bcfdbc Remove specialization of SPEC(OBSERVER) handlers 2020-09-18 00:47:36 +03:00
Nikita Popov
e3d0bc0a98 Fixed bug #80109
Skip over leading EXT_NOP, if it exists.
2020-09-17 09:59:51 +02:00
Bob Weinand
6d538e83aa Fix OSS Fuzz issue: yielding from an aborted generator 2020-09-15 20:07:33 +02:00
Nikita Popov
7e61c2edd8 Fix uninitialized run-time cache when resolving named param defaults
Fixes oss-fuzz #25676.
2020-09-15 16:51:56 +02:00
Nikita Popov
3c53732332 Fix undef var exception handling in JMP_NULL
We need to initialize the result variable in the exceptional
case as well.

Fixes oss-fuzz #25526.
2020-09-15 15:44:01 +02:00
Nikita Popov
a009d370e9 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix assumption about property guard hash value
2020-09-15 15:27:17 +02:00
Nikita Popov
2bbf2a91aa Fix assumption about property guard hash value
The "member" string here does not necessarily have a pre-calculated
hash value. In particular this is not the case if the class has no
properties.

Fixes oss-fuzz #25546.
2020-09-15 15:26:41 +02:00
Nikita Popov
16b9f19678 Fix compile-time/run-time discrepancies with unary operators
This addresses two issues:
 * ~ throws for a number of types, and we should not compile-time
   evaluate in that case. Add a check similar to what we do for
   binary ops.
 * Unary +/- may produce a different error message due to
   canonicalization of the constant operand to the RHS. To avoid
   this, put the constant operand on the RHS right away.

Fixes oss-fuzz #25649.
2020-09-15 15:08:55 +02:00
Máté Kocsis
c37a1cd650
Promote a few remaining errors in ext/standard
Closes GH-6110
2020-09-15 14:26:16 +02:00
Nikita Popov
da0663a337 Add GC_TRY_ADDREF macro
That adds a ref if not immutable. Also audit uses of GC_IMMUTABLE
to either use GC_TRY_ADDREF or GC_TRY_PROTECT_RECURSION.
2020-09-15 11:41:09 +02:00
Christoph M. Becker
edddddcea8 7.3.24 is next 2020-09-15 10:51:41 +02:00
Dmitry Stogov
8f93709d7d micro-optimization 2020-09-15 09:39:41 +03:00
Dmitry Stogov
3228d685e2 Renumber ZEND_ACC_... constants 2020-09-15 09:39:27 +03:00
Bob Weinand
452f7b0d41 Fix use-after-free with yield from in yield_from_multi_tree_single_nodes.phpt
Prevent release of generator children during destruction
2020-09-14 23:07:01 +02:00
Bob Weinand
ad61e141dd Fix crashes with unproper cleaning of repeated yield from
Closes GH-6130
2020-09-14 20:49:24 +02:00
Benjamin Eberlei
1359a52d5b Rename zend_error_notify APIs to zend_observer_error* 2020-09-14 19:29:14 +02:00
Larry Garfield
96f2f3174b Update array parameter names for named parameters
* The array "subject" of a function gets called $array.

* Further parameters should be self-descriptive if used
  as a named parameter, and a full word, not an abbreviation.

* If there is a "bunch more arrays" variadic, it gets
  called $arrays (because that's what was already there).

* A few functions have a variadic "a bunch more arrays,
  and then a callable", and were already called $rest.
  I left those as is and died a little inside.

* Any callable provided to an array function that acts
  on the array is called $callback. (Nearly all were already,
  I just fixed the one or two outliers.)

* array_multisort() is beyond help so I ran screaming.
2020-09-14 14:56:49 +00:00
Nikita Popov
57a4a2c5a8 Fixed bug #80096
We shouldn't assume that call->prev_execute_data is NULL here. The
value needs to be preserved for call chains.
2020-09-14 15:49:49 +02:00
George Peter Banyard
31ef94cd42 Convert Division by 0 warnings to Error per the Engine Warning RFC
Closes GH-6125
2020-09-14 13:40:07 +02:00
Máté Kocsis
46c0c82a0f
Declare array|int and object-of-class|int types in stubs
Closes GH-6081

Co-Authored-By: Nikita Popov <nikic@php.net>
2020-09-14 11:59:32 +02:00
Máté Kocsis
7e0631e5ee
Add Z_PARAM_OBJ_OF_CLASS ZPP macro 2020-09-14 11:40:27 +02:00
Christoph M. Becker
853b7945bc Unmark tests as XFAIL on Windows
This issue has been resolved[1], so the tests are expected to pass on
Windows again.

[1] <0a03291b51>
2020-09-14 10:14:21 +02:00
Christoph M. Becker
71de8fe9b8 Mark tests as XFAIL on Windows
These tests segfault with tracing JIT on Windows as of a recent
commit[1].  A link to a backtrace is available in a comment[2].  For
now, we mark these tests as XFAIL, to keep AppVeyor CI helpful.

[1] <7b0a053169>
[2] <7b0a053169 (commitcomment-42267637)>
2020-09-13 15:38:58 +02:00
Máté Kocsis
3053f6f2fa
Fix prototype of get_active_function_or_method_name() 2020-09-12 19:10:48 +02:00
Nikita Popov
b7fe1b66d0 Make argument type error message consistent for variadics
If an argument error refers to a variadic argument, we normally
do not print the name of the variadic (as it is not referring to
an individual argument, but to the collection of all of them).
However, this was not the case for the userland argument type
error message, which did it's own formatting.

Closes GH-6101.
2020-09-11 17:16:19 +02:00
Máté Kocsis
c98d47696f
Consolidate new union type ZPP macro names
They will now follow the canonical order of types. Older macros are
left intact due to maintaining BC.

Closes GH-6112
2020-09-11 11:00:18 +02:00
Hailong Zhao
9e3e83459c Remove the duplicate line in zend_ast.c
Closes GH-6107.
2020-09-11 09:51:44 +02:00
Dmitry Stogov
7b0a053169 JIT for ASSIGN_OBJ 2020-09-10 23:41:50 +03:00
Dmitry Stogov
e9b47df14f Fixed 32-bit JIT 2020-09-10 16:55:08 +03:00
Tyson Andre
09904242af Avoid gap in AST_CLASS child nodes for attributes
See https://github.com/nikic/php-ast/pull/181

> Hm, I'm thinking it would make more sense to change the structure in php-src.
> All the function types have consistent AST structure, but there's no reason at
> all why classes should be consistent with functions.

It's unusual to have an unused child node between other child nodes that are
used (for name, extends, implements, and attributes of AST_CLASS)

> That gap is a leftover from a previous refactoring. An earlier version of
> attributes extended `zend_ast_decl` with a new member called `attributes` and
> therefore did not need to handle functions and classes in different ways.

Closes GH-6088
2020-09-10 09:33:46 -04:00
Remi Collet
8710429283 fix zend_hash_get_current_key_type_ex proto 2020-09-10 12:40:47 +02:00
Remi Collet
7be70c6bfc fix zend_hash_get_current_key_ex proto 2020-09-10 12:36:44 +02:00
twosee
bd1d11d352 Simplify error type filter
Closes GH-6049.
2020-09-10 17:36:04 +08:00
Nikita Popov
73ab7b30ca Allow array_diff() and array_intersect() with single array argument
Both of these functions are well-defined when used with a single
array argument -- rejecting this case was an artificial limitation.
This is not useful when called with explicit arguments, but removes
edge-cases when used with argument unpacking:

    // OK even if $excludes is empty.
    array_diff($array, ...$excludes);

    // OK even if $arrays contains a single array only.
    array_intersect(...$arrays);

This matches the behavior of functions like array_merge() and
array_push(), which also allow calls with no array or a single
array respectively.

Closes GH-6097.
2020-09-09 11:03:17 +02:00
Máté Kocsis
9975986b7e
Improve error messages mentioning parameters instead of arguments
Closes GH-5999
2020-09-09 10:47:43 +02:00
twosee
40e5238a00 Flesh out ZEND_HASH_REVERSE_FOREACH_* macros
Closes GH-6080.
2020-09-09 15:12:18 +08:00
Nikita Popov
cf8d7b3eae Don't handle missing value in zend_verify_arg_error()
This error condition is handled separately, never reaches this
function.
2020-09-08 20:42:45 +02:00
Dmitry Stogov
a6a96116ac micro-optimization 2020-09-08 16:47:30 +03:00
Nikita Popov
7e339a335e Make null byte error a ValueError
Currently we treat paths with null bytes as a TypeError, which is
incorrect, and rather inconsistent, as we treat empty paths as
ValueError. We do this because the error is generated by zpp and
it's easier to always throw TypeError there.

This changes the zpp implementation to throw a TypeError only if
the type is actually wrong and throw ValueError for null bytes.
The error message is also split accordingly, to be more precise.

Closes GH-6094.
2020-09-08 15:23:23 +02:00
Dmitry Stogov
aae50328e2 decbin/decoct/dechex optimization. 2020-09-08 10:34:29 +03:00
Ilija Tovilo
8a49310f4e
Adjust assignment line number for match
Otherwise the assignment will have the same number as the default arm
which will 1. mis-trigger a breakpoint and 2. mark the line as covered
even when it isn't.

Closes GH-6083
2020-09-08 00:08:18 +02:00
Dmitry Stogov
4a2ae84188 Add "const". Move constant strings to read-only memory. 2020-09-07 21:35:48 +03:00
Nikita Popov
174dadf6b4 Don't allow dynamic properties on generators
Noticed this because we leak those properties in GC. This was
never intended to be allowed.
2020-09-07 19:08:04 +02:00
Nikita Popov
f5dbebd82e Accept zend_string instead of zval in zend_compile_string 2020-09-07 11:42:21 +02:00
Tyson Andre
ace876cdd6 Fix incorrect/unused macro
zend_ts_hash_init accepts 4 arguments, not 5.
The pHashFunction parameter was removed in 5d25762646

Closes GH-6087
2020-09-06 13:05:02 -04:00
Máté Kocsis
e50449bcb4
Use the canonical order of types in array|string ZPP error messages 2020-09-04 14:32:33 +02:00
Máté Kocsis
e50cb320b4
Add the Z_PARAM_ARRAY_HT_OR_NULL and Z_PARAM_OBJ macros 2020-09-04 14:31:27 +02:00
Nikita Popov
2e218180ef Release call trampolines in zpp fcc
When using zpp 'f' or Z_PARAM_FUNC, if the fcc points to a call
trampoline release it immediately and force zend_call_function
to refetch it. This may require additional callability checks
if __call is used, but avoids the need to carefully free fcc
values in all internal functions -- in some cases this is not
simple, as a type error might be triggered by a later argument
in the same zpp call.

This fixes oss-fuzz #25390.

Closes GH-6073.
2020-09-04 14:23:14 +02:00
Nikita Popov
fc8cfb1b1a Merge branch 'PHP-7.4'
* PHP-7.4:
  Avoid duplicate octal warning during heredoc scan ahead
2020-09-04 11:00:45 +02:00
Nikita Popov
e0a14bce77 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Avoid duplicate octal warning during heredoc scan ahead
2020-09-04 10:59:41 +02:00
Nikita Popov
e8d36ce762 Avoid duplicate octal warning during heredoc scan ahead 2020-09-04 10:58:51 +02:00
Nikita Popov
cd1c36f772 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #80049
2020-09-03 17:13:47 +02:00
Nikita Popov
2dabc4c305 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #80049
2020-09-03 17:12:58 +02:00
Nikita Popov
46a49be6c8 Fixed bug #80049
Type checking may convert to refcounted values, so force freeing
of extra args.
2020-09-03 17:12:40 +02:00
Levi Morrison
94fd52dd09 Add Z_PARAM_ITERABLE and co 2020-09-03 07:03:12 -06:00
George Peter Banyard
7b3ac296a5 Fix mismatch between macro and struct definition 2020-09-03 14:01:45 +02:00
Nikita Popov
9464576f29 Fix leaks in sapi tests
Make sure to always free compiled_filename on shutdown.
2020-09-03 12:59:30 +02:00
Nikita Popov
7620ea1580 Don't intern compiled_filename
For php-ast interning the file name is an effective memory leak,
see php-ast#134.

I don't think there's any reason to do this. At some point this
was needed due to bugs in the interned string mechanism that
caused issues if the string was later interned, e.g. through a
__FILE__ reference. These issues have since been resolved.

In conjunction with the filenames_table removal in c4016ecd44
this means that filenames now need to be refcounted like normal
strings. In particular the filename reference in op_arrays and CEs
are refcounted.
2020-09-03 12:31:23 +02:00
Nikita Popov
c4016ecd44 Remove CG(filenames_table)
This doesn't seem to serve any purpose anymore.
2020-09-03 11:33:54 +02:00
Nikita Popov
8516434a56 Fixed bug #80046
We already protect against optimizing away loop frees in DFA pass,
but not in block pass.
2020-09-03 11:19:04 +02:00
Nikita Popov
ce74ff2b3d Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #80046
2020-09-03 11:18:11 +02:00
Nikita Popov
04e77d2dea Fixed bug #80046
We already protect against optimizing away loop frees in DFA pass,
but not in block pass.
2020-09-03 11:18:01 +02:00
Nikita Popov
3b853c97f3 Fixed bug #80045
Applying the obvious fix ... however, I think we may need to
rething how we handle trampoline fcc for "f" zpp. It might make
sense to use fcc->function_handler == NULL for that case and
force it to be fetched in zend_call_function instead (it will
be reset to that after the call anyway). Otherwise we will keep
chasing these leaks, as it's the only instance where it's
necessary to free a zpp result.
2020-09-03 10:29:18 +02:00
Nikita Popov
daf222c9f8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Handle memory limit error during string reallocation correctly
2020-09-03 09:51:54 +02:00
Nikita Popov
0fc65ed133 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Handle memory limit error during string reallocation correctly
2020-09-03 09:51:35 +02:00
Nikita Popov
573ad182d2 Handle memory limit error during string reallocation correctly
Do not decrement the refcount before allocating the new string,
as the allocation operation may bail out and cause a use-after-free
lateron. We can only decrement the refcount once the allocation
has succeeded.

Fixes oss-fuzz #25384.
2020-09-03 09:49:29 +02:00
Benjamin Eberlei
8b37c1e993 Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
Dmitry Stogov
0d157cf526 Micro-optimization 2020-09-02 17:31:48 +03:00
Frank Du
c3299d7dab X86: Fast CRC32 computation using PCLMULQDQ instruction
Based on:
"Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction"
V. Gopal, E. Ozturk, et al., 2009, http://intel.ly/2ySEwL0

Signed-off-by: Frank Du <frank.du@intel.com>

Closes GH-6018
2020-09-02 15:10:41 +02:00
Máté Kocsis
3e800e997b
Move custom type checks to ZPP
Closes GH-6034
2020-09-02 11:11:38 +02:00
Nikita Popov
ddc2a2d381 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix throwing of yield from related exceptions into generator
2020-09-02 10:53:44 +02:00
Nikita Popov
c6fd37cee3 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix throwing of yield from related exceptions into generator
2020-09-02 10:53:13 +02:00
Nikita Popov
2e9e706a82 Fix throwing of yield from related exceptions into generator
Use the general zend_generator_throw_exception() helper for this.
Otherwise we don't handle the off-by-one opline correctly (should
we maybe just stop doing that?)

This is a followup to ad750c3bb6,
which fixed a different yield from exception handling problem that
happened to show up in the same test case from oss-fuzz #25321.
Now both issues should be fixed.
2020-09-02 10:52:55 +02:00
Nikita Popov
8b6b2bda09 Fix by-ref list assign LIST_W+MAKE_REF separation
Shift the responsibility for emitting MAKE_REF to the list assignment
code, to make sure that LIST_W and MAKE_REF are directly adjacent,
and there are no opcodes in between that could modify the LIST_W
result.

Additionally, adjust the zend_wrong_string_offset() code to not
perform a loop over opcodes and assert that the next opcode is
a relevant one. The VM write-safety model requires this.

This is a followup to a07c1f56aa
and the full fix for oss-fuzz #25352.
2020-09-02 10:26:55 +02:00
Nikita Popov
aedc7b0fb4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix infinite loop on string offset during by-ref list assign
2020-09-02 10:16:46 +02:00
Nikita Popov
605ee9c8eb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix infinite loop on string offset during by-ref list assign
2020-09-02 10:16:35 +02:00
Nikita Popov
a07c1f56aa Fix infinite loop on string offset during by-ref list assign
There is a deeper underlying issue here, in that the opcodes violate
VM write-fetch safety, but let's fix the infinite loop first.

This fixes oss-fuzz #25352.
2020-09-02 10:16:05 +02:00
Nikita Popov
a8687804bb Disable ifunc resolvers under dataflow sanitizer
As with other sanitizers, this is not supported.
2020-09-01 20:37:43 +02:00
Nikita Popov
c6ea0e90c2 Assert there are children in zend_generator_get_child() 2020-09-01 20:37:43 +02:00
Levi Morrison
66c3e900e2 Add zend_observer API
Closes GH-5857.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
Co-authored-by: Sammy Powers <sammyk@datadoghq.com>
2020-09-01 09:59:59 -06:00
Máté Kocsis
f7fbc6333f
Add more precise type info for stubs
Closes GH-6005
2020-09-01 16:35:56 +02:00
Nikita Popov
88a8ebce6a Merge branch 'PHP-7.4'
* PHP-7.4:
  Check for null EX(func) in write_property
2020-09-01 15:17:28 +02:00
Nikita Popov
f92a03627a Check for null EX(func) in write_property
This can happen if zend_call_function inserted a dummy frame,
and we already switched to the dummy frame in leave_helper,
and an exception is thrown during CV destruction.

Fixes oss-fuzz #25343.
2020-09-01 15:16:41 +02:00
George Peter Banyard
5c1cf7669b Prepend compiler warning flags to CFLAG instead to append them
Credit to @bwoebi for the idea

Closes GH-6057
2020-09-01 14:45:57 +02:00
Nikita Popov
48e31be7a3 Fix FE_FETCH_R_SIMPLE specialization
After a99d08b5d1 the type can
include UNDEF. However, UNDEF can only reach FE_FREE, not FE_FETCH.
As such, simply ignore this type.
2020-09-01 14:43:06 +02:00
Nikita Popov
a99d08b5d1 Fix type inference for FE_RESET on invalid type
FE_RESET sets the result to UNDEF in this case. We should infer
some type here, because no type generally implies unreachable
code. In this case SCCP ended up replacing the FE_RESET result
with null, including in FE_FREE.
2020-09-01 13:59:36 +02:00
Nikita Popov
c088a9369f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix pi node removal when removing predecessor
2020-09-01 12:26:18 +02:00
Nikita Popov
37612936a1 Fix pi node removal when removing predecessor
We can't just remove the uses, we need to replace uses.

The test case only fails on master with SSA integrity violations,
but I believe the root issue also existed previously.
2020-09-01 12:25:00 +02:00
Nikita Popov
4acac9bd72 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix leak on assign concat of array and empty string
2020-08-31 17:06:21 +02:00
Nikita Popov
9560e3ba7a Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix leak on assign concat of array and empty string
2020-08-31 17:05:55 +02:00
Nikita Popov
cd2afd99b1 Fix leak on assign concat of array and empty string 2020-08-31 17:05:31 +02:00
Nikita Popov
2022f2e5c9 Fix nullsafe operator with delayed oplines
Closes GH-6056.
2020-08-31 16:44:36 +02:00
Ilija Tovilo
70300f6c9d Add tests for nullsafe operator on delayed oplines 2020-08-31 16:44:36 +02:00
Nikita Popov
50975640bc Fixed bug #80030 2020-08-31 12:38:11 +02:00
Nikita Popov
570f463fb8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #80037
2020-08-31 12:19:00 +02:00
Nikita Popov
dfaa4768d2 Fix bug #80037
If we're accessing an uninitialized typed property and __get is
defined, don't perform a read_property callback, as __get is
supposed to have no effect on uninitialized typed properties.
Usually it doesn't, but by-reference assignments cannot be
performed through read_property.

I'm deleting the test for bug #80039 again, as it doesn't really
make sense anymore with this fix.
2020-08-31 12:17:00 +02:00
Nikita Popov
0e9d76ee62 Merge branch 'PHP-7.4'
* PHP-7.4:
  Add test for bug #80039
2020-08-31 11:22:51 +02:00
Nikita Popov
8f7c529720 Add test for bug #80039
This has already been fixed by 247105ae1a,
but let's add the additional test case.
2020-08-31 11:22:16 +02:00
Nikita Popov
ad97739eac Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix handling of exception if valid() during yield from
2020-08-31 10:52:07 +02:00
Nikita Popov
b396fb348b Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix handling of exception if valid() during yield from
2020-08-31 10:51:49 +02:00
Nikita Popov
ad750c3bb6 Fix handling of exception if valid() during yield from
Fixes oss-fuzz #25296.
2020-08-31 10:51:31 +02:00
Nikita Popov
061c708a93 Correctly report failure in zend_handle_undef_args()
And do the check before increfing the closure object, otherwise
we'd have to release it as well.

Fixes oss-fuzz #25313.
2020-08-31 10:37:55 +02:00
Nikita Popov
e81becce08 Fix trampoline leak in array_map 2020-08-31 10:14:39 +02:00
Jamie Liu
c8093fe94a Fix bug #80018: Tolerate var_dump() printing floats in exponential notation in tests 2020-08-31 09:51:01 +02:00
twosee
f982038fb6 Merge branch 'PHP-7.4'
* PHP-7.4:
  Improve error_handing replacement functions

# Conflicts:
# Zend/zend_API.c
2020-08-30 17:06:59 +08:00
twosee
45ed9b42a5 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Improve error_handing replacement functions
2020-08-30 16:25:12 +08:00
twosee
e948188832 Improve error_handing replacement functions
We explicitly skip calls to user_error_handler in EH_THROW mode

Closes GH-6050.
2020-08-30 16:24:42 +08:00
Nikita Popov
86364013f9 Avoid ubsan warning with dummy cache slot addr 2020-08-28 17:24:21 +02:00
Nikita Popov
927771333b Fix unused variable warning 2020-08-28 17:19:32 +02:00
Nikita Popov
b2bc2c62fa Remove unnecessary cache_slot arguments
zend_verify_type_error_common() no longer needs the cache_slot,
so drop it there and from all users.
2020-08-28 17:15:09 +02:00
Nikita Popov
2c15c9ce80 Rehash function table after disabling functions
To perform fast shutdown without full table cleanup we need all
internal functions to be in one continuous chunk. This was
violated when functions were deleted via disable_functions.

This drops the zend_disable_function() API in favor of
zend_disable_functions(), which disables the given list of
functions and performs the necessary rehash afterwards.

Also drop PG(disabled_functions), which is no longer used.
2020-08-28 16:50:07 +02:00
Nikita Popov
138f141605 Don't mark variadic functions as ZEND_FASTCALL
Variadic functions do not support the fastcall calling convention.
2020-08-28 16:45:13 +02:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics

Closes GH-6002
2020-08-28 15:41:27 +02:00
Nikita Popov
5db44e39b1 Fix tracked_realloc
We should only drop the information about the old allocation after
checking the memory limit. This makes the code a bit more awkward...
2020-08-28 11:37:42 +02:00
Nikita Popov
32315c247f Promote incomplete class to modification to Error
In line with engine diagnostic promotions, property writes throw
an Error exception, while reads throw a warning.
2020-08-28 11:14:43 +02:00
Nikita Popov
df5011f56c Export and reuse zend_is_valid_class_name API
Unserialization does the same check as zend_lookup_class, so let's
share the same optimized implementation.
2020-08-28 10:06:01 +02:00
Nikita Popov
a2bbd8f01f Fix leak in typed reference assignment
We're only creating tmp here to compare against the existing
coerced_value. We need to destroy it in all cases.
2020-08-27 14:40:35 +02:00
Nikita Popov
614c0b846e Allow removing non-existing key from WeakMap
In line with usual PHP semantics. This previously triggered an
assertion failure.
2020-08-27 12:42:08 +02:00
Nikita Popov
0026d8a783 Fix use-after-free is WeakMap key and value are the same
Drop the object from the WeakMap as the last step, as this might
end up destroying the object.
2020-08-27 12:05:06 +02:00
Nikita Popov
bd6feb7b12 Enforce memory limit in tracked allocation mode
A very basic limit (for single allocations) was already enforced.
This extends it to count the total memory allocations.

This is useful to avoid out of memory conditions while fuzzing.
2020-08-27 10:18:18 +02:00
Nikita Popov
e069032e5c Merge branch 'PHP-7.4'
* PHP-7.4:
  Property handle read_property exception in fetch_property_address
2020-08-26 16:13:10 +02:00
Nikita Popov
247105ae1a Property handle read_property exception in fetch_property_address
Otherwise we leak (and corrupt uninitialized_zval).
2020-08-26 16:12:34 +02:00
Nikita Popov
55798e0e39 Lowercase method name in zend_call_method() 2020-08-26 15:19:23 +02:00
Nikita Popov
86cd009718 Fix pass by ref error for named params 2020-08-26 15:10:08 +02:00
George Peter Banyard
1b2ec73c1d Drop various unused macros/APIs
Also convert_libmagic_pattern() to return a zend_string*

Closes GH-6029
2020-08-26 12:59:43 +02:00
Nikita Popov
795ad1e354 Fix memory leak on unknown named param in iterator unpack 2020-08-26 12:19:17 +02:00
Nikita Popov
1003ae2692 Fix passing of undef var to named arg
This needs to use the previously computed argument target.
2020-08-26 11:53:02 +02:00
Nikita Popov
492621f99e Fix memory leak on unknown named param 2020-08-26 11:44:15 +02:00
Nikita Popov
d7d2b060e1 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix memory leak when yielding from non-iterable
2020-08-26 11:32:56 +02:00
Nikita Popov
bf3e772361 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix memory leak when yielding from non-iterable
2020-08-26 11:32:31 +02:00
Nikita Popov
d179e34e42 Fix memory leak when yielding from non-iterable 2020-08-26 11:32:01 +02:00
Nikita Popov
1954aed745 Fix over-eager named params optimization
We can't relax a named param to a positional param if we encountered
any unknown parameters in the meantime.
2020-08-26 11:01:15 +02:00
Dmitry Stogov
2369f48092 Infer information about packed/hash arrays and use it for JIT 2020-08-25 18:28:23 +03:00
Máté Kocsis
6c8fb123d2
Promote warnings to exceptions in ext/simplexml
Closes GH-6011

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-08-25 15:15:58 +02:00
twosee
9f05c32704 Remove useless same_zval function
Closes GH-6039.
2020-08-25 18:02:38 +08:00
Nikita Popov
7a6ae9b148 Fix refcounting for the named params case as well
Adjust the test case to pass a refcounted value and to also check
the named params case.
2020-08-24 16:30:49 +02:00
Nikita Popov
779e904465 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix refcounting
2020-08-24 16:23:33 +02:00
Nikita Popov
bb54694f4f Fix refcounting 2020-08-24 16:23:19 +02:00
Christoph M. Becker
5643f34a1e Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #79979: passing value to by-ref param via CUFA crashes
2020-08-24 15:03:26 +02:00
Christoph M. Becker
6b6c2c003c Fix #79979: passing value to by-ref param via CUFA crashes
If a by-val send is not allowed, we must not do so.  Instead we wrap
the value in a temporary reference.

Closes GH-6000
2020-08-24 14:08:32 +02:00
Nikita Popov
9395e01e3d Check variadic parameter for type and duplicate name
Set HAS_TYPE_HINTS flag if the variadic parameter is types as well,
and make sure it has a distinct name. This was previously missed,
because the variadic parameter is not part of num_args.
2020-08-24 10:15:57 +02:00
Dmitry Stogov
5c18ee58b9 Fixed use-after-free introduced by aed1f78515 2020-08-24 09:50:54 +03:00
Christoph M. Becker
13419befff Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix wrong datatype
2020-08-21 15:30:07 +02:00
Christoph M. Becker
8f9f308bb9 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix wrong datatype
2020-08-21 15:28:37 +02:00
Manuel Mausz
46d62e5464 Fix wrong datatype
ini_entry->modifiable is of type uint8_t and so should be the temp. variable. Especially important after 4b77a158.

Closes GH-6028
2020-08-21 15:28:12 +02:00
Dmitry Stogov
aed1f78515 micro-optimization 2020-08-20 15:02:12 +03:00
Christoph M. Becker
ff14b7adad 7.3.23 is next 2020-08-18 09:55:37 +02:00
Nikita Popov
befe10fd21 Fix bug #78770
Refactor the zend_is_callable implementation to check callability
at a particular frame (this is an implementation detail for now,
but could be exposed in the API if useful). Pick the first parent
user frame as the one to check.
2020-08-14 10:24:06 +02:00
Nikita Popov
b03e300a29 Fix test after PDOStatement::fetchObject() change 2020-08-13 16:45:32 +02:00
Nikita Popov
670036e2a9 Use Z_PARAM_CLASS in PDOStatement::fetchObject()
Instead of implementing custom logic.
2020-08-13 16:20:29 +02:00
Tyson Andre
1e9a5c67ef Rename standard array function parameters to $array
This is targeting 8.0.

`$arg` seems like a poor choice of a name,
especially if the function were to have arguments added.

In many cases, the php.net documentation already has $array for these functions.
E.g. https://www.php.net/manual/en/function.array-intersect.php

I'd assume that since named arguments was added to 8.0 near the feature freeze,
PHP's maintainers had planned to make the names consistent
and gradually use the same name for  docs and implementation.
2020-08-11 19:11:59 -04:00
Ilija Tovilo
10f660f0a5
Fix ?-> in encaps vars without braces
Closes GH-5966.
2020-08-11 21:16:44 +02:00
Nikita Popov
e25aab6426 Fixed bug #79927
We need to unset the AT_FIRST_YIELD flag when yielding from an
array as well.

In the interest of being conservative, I'm applying this only to
PHP 8.
2020-08-11 15:48:40 +02:00
Nikita Popov
227f1f1481 Fix nullsafe operator on $this 2020-08-11 15:22:14 +02:00
Nikita Popov
42eda5160d SAVE_OPLINE in NULL_HANDLER
Let's avoid crashing before the nice error message gets printed...
2020-08-11 15:14:50 +02:00
Nikita Popov
f491dabe40 Fix nullsafe operator on reference
Dereference the value before checking the type. As the happy path
necessarily has to check for references, I'm not bothering to
delay the comparison.
2020-08-11 15:11:36 +02:00
Nikita Popov
c439f1fa6a Fixed bug #62294
The primary issue was already resolved in 7c3e487289,
but the particular example used in this bug report ran into an
additional issue on PHP 8, because I forgot to drop a number of
zend_bailout calls when switch require failure to throw.
2020-08-10 12:54:02 +02:00
Nikita Popov
ee16316148 Fixed bug #79948
Make sure we don't execute further scripts if one of them encountered
an exit exception.

Also make sure that we free file handles that end up unused due to
an early abort in php_execute_scripts(), which turned up as an
issue in the added test case.

Finally, make use of EG(exit_status) in the places where we
zend_eval_string_ex, instead of unconditionally assigning exit
code 254. If an error occurs, the error handler will already set
exit status 255.
2020-08-10 11:15:16 +02:00
Nikita Popov
896dad4c79 Fixed bug #77561
Unconditionally strip shebang lines when using the CLI SAPI,
independently of whether they occur in the primary or non-primary
script. It's unlikely that someone intentionally wants to print
that shebang line when including a script, and this regularly
causes issues when scripts are used in multiple contexts, e.g.
for direct invocation and as a phar bootstrap.
2020-08-10 10:38:33 +02:00
Nikita Popov
74c4381806 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79947
2020-08-10 10:13:34 +02:00
Nikita Popov
2d087210eb Fixed bug #79947
Move the FREE_OP for op_data out of the zend_binary_assign_op_dim_slow()
slow path, so it can be used by the other error path as well. This
makes ASSIGN_DIM_OP structurally more similar to ASSIGN_DIM.
2020-08-10 10:11:56 +02:00
Máté Kocsis
7aacc705d0
Add many missing closing PHP tags to tests
Closes GH-5958
2020-08-09 22:03:36 +02:00
Nikita Popov
8b77c58130 Accept zend_object* in zend_update_property 2020-08-07 16:40:27 +02:00
Nikita Popov
01cbb5967c Accept zend_object* in zend_unset_property 2020-08-07 16:40:27 +02:00
Nikita Popov
978b7de244 Accept zend_object* in zend_get_exception_base 2020-08-07 16:40:27 +02:00
Nikita Popov
7991fc2753 Accept zend_object in zend_read_property 2020-08-07 16:40:27 +02:00
Máté Kocsis
af80d8a14e
Add more argument types to stubs
Closes GH-5943
2020-08-07 12:35:30 +02:00
Nikita Popov
fcff418411 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #79934: CRLF-only line in heredoc causes parsing error
2020-08-06 12:04:23 +02:00
Nikita Popov
2cbc94097e Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79934: CRLF-only line in heredoc causes parsing error
2020-08-06 12:03:57 +02:00
Pieter van den Ham
06ade15528 Fix #79934: CRLF-only line in heredoc causes parsing error
Fixes the function `next_newline()` in zend_language_scanner.l. The
function now correctly returns a newline_len of 2 for "\r\n".

Closes GH-5944.
2020-08-06 12:02:54 +02:00
Gabriel Caruso
7479ab9f80 Update API version numbers
In preparation for PHP 8.0.
2020-08-04 22:25:28 +02:00
Nikita Popov
0d836a39a7 Revert "Prepare for PHP 8.1"
This reverts commit 1ab4d0e6b7.
This reverts commit a359635cb1.
2020-08-04 22:24:44 +02:00
Gabriel Caruso
a359635cb1
Prepare for PHP 8.1 2020-08-04 18:46:14 +02:00
Gabriel Caruso
1ab4d0e6b7
Update API version numbers
In preparation for PHP 8.0.
2020-08-04 18:07:16 +02:00
Levi Morrison
9b975fe98e Merge branch 'levim/assert-throw'
This changes assert.exception to default to 1, or on by default.
Closes GH-5925.
2020-08-03 08:04:48 -06:00
Nikita Popov
dc1107ba5b Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Removed space from bug55086.phpt
2020-08-03 15:14:36 +02:00
Graham Campbell
f3a43e85e7 Removed space from bug55086.phpt
Closes GH-5923.
2020-08-03 15:14:15 +02:00
Nikita Popov
c48b745f00 Promote "undefined array key" notice to warning
This implements the last remaining part of the
https://wiki.php.net/rfc/engine_warnings RFC.

Closes GH-5927.
2020-08-03 14:40:50 +02:00
Nikita Popov
bb8b95be63 Fix bug #79925
If the expected return type of a magic method is "object", we also
need to allow class types and "static" to comply with covariance.
2020-08-03 10:35:26 +02:00
Nikita Popov
5d4659c25c Enforce __set_state() parameter type
This fixes one of the issues reported in bug #79925. The parameter
type check for this particular method was missed.
2020-08-03 10:23:06 +02:00
Nikita Popov
a4c015b4b2 Fix handling of nullsafe method in empty()
Fixes oss-fuzz #24627.
2020-08-03 10:16:38 +02:00
tangl163
7d4ae7fa23 Drop the unneeded pointer casting
The standard says that "A pointer to void may be converted to or from a
pointer to any object type". So the casting is unneeded.

REF:
    * c11: http://port70.net/~nsz/c/c11/n1570.html#6.3.2.3p1
    * c99: http://port70.net/~nsz/c/c99/n1256.html

Closes GH-5916
2020-08-03 02:05:14 +01:00
Levi Morrison
853eb8373f Default assert.exception to 1 2020-08-02 13:39:35 -06:00
Gabriel Caruso
e3d06fc79d
Ensure correct signatures for magic methods 2020-08-02 01:29:56 +02:00
Nikita Popov
d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00
Nikita Popov
a6e63b42c3 Make check in RECV_VARIADIC more precise
Fetch arg_info only once (it's always the same one...) and check
ZEND_TYPE_IS_SET on it, rather than checking if *any* parameter
has a type.
2020-07-31 12:02:28 +02:00
Christoph M. Becker
8c4f7d668e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #79919: Stack use-after-scope in define()
2020-07-31 10:59:17 +02:00
Christoph M. Becker
fce8061ede Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79919: Stack use-after-scope in define()
2020-07-31 10:57:02 +02:00
Christoph M. Becker
1e0bc6e30f Fix #79919: Stack use-after-scope in define()
Instead of the temporary `rv`, we use the `val_free` which is there for
this purpose.
2020-07-31 10:54:41 +02:00
Máté Kocsis
0d330e1a02
Add a few missing parameter types in stubs
Related to GH-5627
2020-07-30 14:26:45 +02:00
Deus Kane
f475edc2f1 Fixed bug #79897: Promoted constructor params with attribs cause crash
This was caused by the attribute AST being used twice, and was fixed by
creating a temporary copy of it (and destroying said copy) when neccesary.
2020-07-30 11:08:31 +02:00
Nikita Popov
ee7eecf321 Fix leak with nullsafe operator with constant LHS
Followup to 5303bcdd32. We need to
perform the addref after emitting the opline, because that might
intern the string.

Fixes oss-fuzz #24479.
2020-07-29 15:51:47 +02:00
Nikita Popov
c206c742d6 Fix bug #79900
Run debug build shutdown GC regardless even if GC has been disabled.
Of course, this only does something meaningful if the GC has been
disabled at runtime and root collection is still enabled. We cannot
prevent leaks if GC is disabled completely.
2020-07-29 15:27:48 +02:00
Nikita Popov
993be4b9bf Fix STR_OR_OBJ_OF_TYPE stringable handling 2020-07-29 11:29:49 +02:00
George Peter Banyard
b2248789ed Implement 'Saner Numeric Strings' RFC:
RFC: https://wiki.php.net/rfc/saner-numeric-strings

This removes the -1 allow_error mode from is_numeric_string functions and replaces it by
a trailing boolean out argument to preserve BC in a couple of places.

Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit
a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError.

This mostly affects:
 - String offsets
 - Arithmetic operations
 - Bitwise operations

Closes GH-5762
2020-07-29 02:51:09 +01:00
Andrea Faulds
f759936591 Permit trailing whitespace in numeric strings
This is part 1 of the 'Saner Numeric Strings' RFC:
https://wiki.php.net/rfc/saner-numeric-strings
2020-07-29 02:22:38 +01:00
Nikita Popov
c434bbb344 Fix typo in test 2020-07-28 15:39:22 +02:00
Theodore Brown
470d1696d9 Implement Shorter Attribute Syntax
RFC: https://wiki.php.net/rfc/shorter_attribute_syntax

Closes GH-5796.

Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-07-28 15:28:57 +02:00
Christoph M. Becker
44ad2db15f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #79806: realpath() erroneously resolves link to link
2020-07-28 14:02:25 +02:00
Christoph M. Becker
e0ebe56ebf Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79806: realpath() erroneously resolves link to link
2020-07-28 14:00:52 +02:00
Christoph M. Becker
c756f82c02 Fix #79806: realpath() erroneously resolves link to link
After resolving reparse points, the path still may be a reparse point;
in that case we have to resolve that reparse point as well.
2020-07-28 13:55:22 +02:00
Nikita Popov
5303bcdd32 Fix use-after-free when nullsafe used with constant LHS
Fixes oss-fuzz #24436.
2020-07-28 09:48:13 +02:00
Christoph M. Becker
592f70bc46 Merge branch 'PHP-7.4'
* PHP-7.4:
  Revert "Fix #79806: realpath() erroneously resolves link to link"
2020-07-27 17:53:23 +02:00
Christoph M. Becker
f02507469d Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Revert "Fix #79806: realpath() erroneously resolves link to link"
2020-07-27 17:51:56 +02:00
Christoph M. Becker
1aeff522b8 Revert "Fix #79806: realpath() erroneously resolves link to link"
This reverts commit d5b59b4303.
2020-07-27 17:50:41 +02:00
Christoph M. Becker
54e15dcd6f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #79806: realpath() erroneously resolves link to link
2020-07-27 15:11:39 +02:00
Christoph M. Becker
85a26fef11 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79806: realpath() erroneously resolves link to link
2020-07-27 15:10:22 +02:00
Christoph M. Becker
d5b59b4303 Fix #79806: realpath() erroneously resolves link to link
After resolving reparse points, the path still may be a reparse point;
in that case we have to resolve that reparse point as well.
2020-07-27 15:08:39 +02:00
Nikita Popov
6d97e7f0e9 JIT internal functions with return type in debug mode
The return type check is just a debug assertion, it's okay if it
is not performed in JIT mode. We already don't perform all the
argument validation in that case. Just disable the one test that
checks for this.

This removes an annoying discrepancy between debug&release mode.
2020-07-27 15:02:59 +02:00
Nikita Popov
08e6c20955 Fix null pointer deref in compile_return()
Fixes oss-fuzz #24387.
2020-07-27 10:27:26 +02:00
Nikita Popov
3b5b288127 Add AST export support for nullsafe operator
Fixes oss-fuzz #24403 and variants.
2020-07-27 10:20:02 +02:00
Derick Rethans
f66627abff Another pass of improving ext/date argument names 2020-07-26 10:38:53 +01:00
Tyson Andre
07db64156e [RFC] Make string length for getTraceAsString() configurable
Add a `zend.exception_string_param_max_len` ini setting.
(same suffix as `log_errors_max_len`)

Allow values between 0 and 1000000 bytes.
For example, with zend.exception_string_param_max_len=0,
"" would represent the empty string, and "..." would represent something
longer than the empty string.
Previously, this was hardcoded as exactly 15 bytes.

Discussion: https://externals.io/message/110717

Closes GH-5769
2020-07-25 09:50:57 -04:00
Máté Kocsis
8664ff7ae1
Cleanup argument handling in ext/reflection
Closes GH-5850
2020-07-24 17:47:42 +02:00
Nikita Popov
1f8a93abaa Support class+mask union for internal argument 2020-07-24 16:40:14 +02:00
Derick Rethans
e96e4ac726 More consistent parameter names for date/time functions 2020-07-24 11:49:01 +01:00
Nikita Popov
d65d3f5298 Fix bug #79108
Don't expose references in debug_backtrace() or exception traces.
This is regardless of whether the argument is by-reference or not.

As a side-effect of this change, exception traces may now acquire
the interior value of a reference, which may be unexpected for
some internal functions. This is what necessitated the change in
the spl_array sort implementation.
2020-07-24 12:23:34 +02:00
Máté Kocsis
70a3a909cd
Add the Z_PARAM_PATH_OR_NULL() and Z_PARAM_ZVAL_OR_NULL() macros 2020-07-24 10:37:35 +02:00
Nikita Popov
0a5b7c81b7 Make nested ternary without parentheses a compile error
This was deprecated in PHP 7.4.
2020-07-24 10:35:42 +02:00
Ilija Tovilo
9bf119832d
Implement nullsafe ?-> operator
RFC: https://wiki.php.net/rfc/nullsafe_operator

Closes GH-5619.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-07-24 10:05:03 +02:00
Christoph M. Becker
1e938e8eba Fix build
MSVC is pretty picky there, so we add the `ZEND_VOIDP` cast.
2020-07-22 22:57:58 +02:00
Christoph M. Becker
f1436c4832 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix minor memory leak of CG(script_encoding_list)
2020-07-22 20:34:21 +02:00
Christoph M. Becker
c1a80e075a Fix minor memory leak of CG(script_encoding_list)
This only leaks at the end of the process, so per se not an issue, but
the leak is caught by MSVC's CRT leak checker, so we better properly
clean up to avoid false positives.
2020-07-22 20:32:48 +02:00
twosee
6e92487f66 Fix warnings of strict-prototypes
Closes GH-5887.
2020-07-23 00:59:00 +08:00
twosee
a65ec4c2db Change type of max_num_args to uint32_t
Closes GH-5885.
2020-07-23 00:55:58 +08:00
twosee
e29ee65ec0 Export zend_register_error_notify_callback() with ZEND_API 2020-07-23 00:45:06 +08:00
Nikita Popov
7a3dcc3e33 Treat namespaced names as single token
Namespace names are now lexed as single tokens of type
T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED or T_NAME_RELATIVE.

RFC: https://wiki.php.net/rfc/namespaced_names_as_token

Closes GH-5827.
2020-07-22 12:36:05 +02:00
Nikita Popov
acbf7802af Improved number to string comparison semantics
RFC: https://wiki.php.net/rfc/string_to_number_comparison

Closes GH-3886.
2020-07-22 12:23:49 +02:00
Tyson Andre
4cf8b6f1c9 Support optional comma in closure use list
RFC: https://wiki.php.net/rfc/trailing_comma_in_closure_use_list
Discussion: https://externals.io/message/110715

The release manager has agreed to allow merging of RFCs that have near-unanimous
votes. If an RFC ends up not achieving the required 2/3 majority at the time the
announced voting period closes, this implementation commit will be reverted
in time for the feature freeze.

Closes GH-5793
2020-07-21 13:01:27 -04:00
Nikita Popov
e079e753dc Give zend_pass_function an arginfo
Now that the ZEND_ACC_VARIADIC flag is set, we should also make
sure there is a variadic arg that can be looked up.
2020-07-21 16:01:45 +02:00
Máté Kocsis
5770b66722
Cleanup argument handling of Zend functions and methods
Closes GH-5847
2020-07-21 14:47:03 +02:00
Nikita Popov
c9881fde7a Run arginfo / zpp mismatch tests for methods as well
As a side-effect, this also catches issues where classes are not
prepared for use with newInstanceWithoutConstructor.
2020-07-21 14:17:29 +02:00
Nikita Popov
38fb1f8383 Check for missing arginfo arguments
Internal functions error when too many arguments are passed. Make
this part of the verification we do in debug builds. This will
help avoid cases where an argument is missing in the stubs,
as recently encountered in 6d96f0f.
2020-07-21 14:17:29 +02:00
Christoph M. Becker
2c0a6977dd 7.3 is now 7.3.22-dev 2020-07-21 09:18:07 +02:00
Nikita Popov
236ddc56a2 Preserve original ce_flags when registering class
Bug that regularly sneaks in: ZEND_ACC_FINAL is set before calling
zend_register_internal_class() and promptly gets ignored. Remove
this footgun by preserving flags from the original CE.
2020-07-20 17:00:04 +02:00
Nikita Popov
7fd4212cc0 Add common code for magic method assignment
This was repeated three times.
2020-07-20 14:57:10 +02:00
Nikita Popov
efce3694b7 Directly assign magic methods
Instead of going through intermediary variables.
2020-07-20 11:22:47 +02:00
Nikita Popov
91e5452b95 Remove unused lc_class_name variable
This is probably a leftover from "old style constructor" support.
2020-07-20 11:15:58 +02:00
Nikita Popov
19de727e04 Report magic method names as written
Report the name the way the user has written it, the same way we
always do.
2020-07-20 11:12:47 +02:00
Nikita Popov
149029b9d6 Unify magic method visibility check
This was missing entirely for the internal function case.
2020-07-20 11:12:47 +02:00
Nikita Popov
312fe2bdce Unify magic method return type checks 2020-07-20 10:51:48 +02:00
Nikita Popov
fbbcf82ab7 Unify static/non-static check for magic methods
And promote it to be fatal.
2020-07-20 10:39:43 +02:00
Nikita Popov
b466e8b754 Add missing arg num check for __set_state 2020-07-20 10:20:29 +02:00
Nikita Popov
dcaf62f3d3 Clean up zend_check_magic_method_implementation
Let everything go through a common function, which fixes some
consistency issues.
2020-07-20 10:17:40 +02:00
Nikita Popov
f9ced0d4f7 Add missing zpp_none call in Exception::__wakeup 2020-07-17 16:06:54 +02:00
George Peter Banyard
fa60f57be4 Drop unused param in zend_parse_arg_class_name_or_obj() 2020-07-17 17:00:27 +02:00
Nikita Popov
86a62eb1fc Fixed bug #79867
In line with usual rules, give untyped properties a null default
value. Otherwise constructor promotion would give you a property
declaration that cannot be achieved through any other means.
2020-07-17 15:10:45 +02:00
Benjamin Eberlei
6c8b94eb42 Introduce error notification callbacks that are run independant of zend_error_cb 2020-07-17 15:08:11 +02:00
Nikita Popov
6d96f0f9ce Fix WeakReference::create() stub 2020-07-16 20:46:45 +02:00
Pedro Magalhães
272b887b7b Ignore inheritance rules on private methods
Closes GH-5401
2020-07-15 17:09:57 +01:00
Nikita Popov
5785a15f4e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79862
2020-07-15 15:00:45 +02:00
Nikita Popov
e8430b592f Fixed bug #79862
While normally a private property in the active scope would take
priority, we should not use this if it has the wrong "staticness".
2020-07-15 14:59:55 +02:00
Nikita Popov
f60cf0cfe7 Remove type argument from zend_get_zval_ptr
As pointed out by Levi, this is unused, and we already changed
the signature of this function for PHP 8.
2020-07-15 09:51:51 +02:00
Nikita Popov
70501b81a7 Fixed bug #79852 2020-07-14 12:31:06 +02:00
George Peter Banyard
4f3eccfd4d Use consistent types
uint32_t type for argument count
size_t for length of char*
zend_bool for a zval bool arg

Closes GH-5845
2020-07-13 13:30:54 +02:00
Rowan Tommins
55a15f32ce Improve output of tokens in Parse Errors
Currently, unexpected tokens in the parser are shown as the text
found, plus the internal token name, including the notorious
"unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)".

This commit replaces that with a more user-friendly format, with
two main types of token:

* Tokens which always represent the same text are shown like
  'unexpected token "::"' and 'expected "::"'
* Tokens which have variable text are given a user-friendly
  name, and show like 'unexpected identifier "foo"', and
  'expected identifer'.

A few tokens have special cases:

* unexpected token """ -> unexpected double-quote mark
* unexpected quoted string "'foo'" -> unexpected single-quoted
  string "foo"
* unexpected quoted string ""foo"" -> unexpected double-quoted
  string "foo"
* unexpected illegal character "_" -> unexpected character 0xNN
  (where _ is almost certainly a control character, and NN is the
   hexadecimal value of the byte)

The \ token has a special case in the implementation just to stop
bison making a mess of escaping it and it coming out as \\
2020-07-13 11:07:40 +02:00
Nikita Popov
213852de78 Fixed bug #79828 2020-07-13 09:55:13 +02:00
Ilija Tovilo
1c967df5a0
Fix free of uninitialized memory in MATCH_ERROR
As suggested by Tyson Andre:
https://github.com/php/php-src/pull/5371#issuecomment-657081464

Also fix line number of unhandled match error

Closes GH-5841.
2020-07-12 13:33:36 +02:00
Ilija Tovilo
d5a0370828
[skip ci] Consistent match test closing tags 2020-07-11 16:50:51 +02:00
Máté Kocsis
95cff3ebf2
Retain the original formatting character in test 2020-07-10 23:15:08 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
George Peter Banyard
2297a6d364 Use dedicated function for illegal offset type error 2020-07-10 16:49:52 +02:00
Nikita Popov
5fc70243d7 Add missing addref for MATCH_ERROR operand 2020-07-10 15:58:42 +02:00