Commit Graph

1008 Commits

Author SHA1 Message Date
Nikita Popov
f5dbebd82e Accept zend_string instead of zval in zend_compile_string 2020-09-07 11:42:21 +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
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
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
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
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
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
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
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +02:00
Nikita Popov
75c4e613e4 Correctly determine arg name of USER_ARG_INFO functions 2020-07-06 11:51:10 +02:00
Nikita Popov
795d2cbd71 Reuse warning function 2020-07-06 10:38:02 +02:00
Nikita Popov
75a04eac97 Make exit() unwind properly
exit() is now internally implemented by throwing an exception,
performing a normal stack unwind and a clean shutdown. This ensures
that no persistent resource leaks occur.

The exception is internal, cannot be caught and does not result in
the execution of finally blocks. This may be relaxed in the future.

Closes GH-5768.
2020-06-29 15:50:12 +02:00
Nikita Popov
1c74bab8e6 More efficient check for valid class name
Use a bitset of valid characters instead of strspn. This is both
more efficient and more compact.
2020-06-10 14:50:35 +02:00
Nikita Popov
5b59d4915c Cleanup SPL autoload implementation
Replace EG(autoload_func) with a C level zend_autoload hook.
This avoids having to do one indirection through PHP function
calls. The need for EG(autoload_func) was a leftover from the
__autoload() implementation.

Additionally, drop special-casing of spl_autoload(), and instead
register it just like any other autoloading function. This fixes
bug #71236 as a side-effect.

Finally, change spl_autoload_functions() to always return an array.
The distinction between false and an empty array no longer makes
sense here.

Closes GH-5696.
2020-06-10 09:38:47 +02:00
Nikita Popov
e56e53a59d Back up fake_scope in zend_call_function
We regularly find new places where we forgot to reset fake_scope.
Instead of having to handle this for each caller of zend_call_function()
and similar APIs, handle it directly in zend_call_function().
2020-06-09 16:33:33 +02:00
Nikita Popov
257dbb0450 Add zend_call_known_function() API family
This adds the following APIs:

void zend_call_known_function(
    zend_function *fn, zend_object *object, zend_class_entry *called_scope,
    zval *retval_ptr, int param_count, zval *params);

void zend_call_known_instance_method(
    zend_function *fn, zend_object *object, zval *retval_ptr, int param_count, zval *params);
void zend_call_known_instance_method_with_0_params(
    zend_function *fn, zend_object *object, zval *retval_ptr);
void zend_call_known_instance_method_with_1_params(
    zend_function *fn, zend_object *object, zval *retval_ptr, zval *param);
void zend_call_known_instance_method_with_2_params(
    zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2);

These are used to perform a call if you already have the
zend_function you want to call. zend_call_known_function()
is the base API, the rest are just really thin wrappers around
it for the common case of instance method calls.

Closes GH-5692.
2020-06-09 16:21:54 +02:00
Dmitry Stogov
bfc56ed511 Keep trace number in EG(jit_trace_num) instead of EG(reserved)[zend_func_info_rid] 2020-05-25 17:05:26 +03:00
Nikita Popov
1b1d313275 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix static property indirections in file cache
  Don't require rc=1 for function static variables
2020-05-20 11:13:35 +02:00
Nikita Popov
8819d247c6 Don't require rc=1 for function static variables
If file cache only is used, then static_variables_ptr may point
to an immutable static_variables HT, which we do not want to
destroy here.
2020-05-20 11:12:18 +02:00
Máté Kocsis
93640db4d5
Improve error message for deprecated methods 2020-05-14 17:23:31 +02:00
Alex Dowad
555489dd83 Honor script time limit when calling shutdown functions
A time limit can be set on PHP script execution via `set_time_limit` (or .ini file).
When the time limit is reached, the OS will notify PHP and `timed_out` and `vm_interrupt`
flags are set. While these flags are regularly checked when executing PHP code, once the
end of the script is reached, they are not checked while invoking shutdown functions
(registered via `register_shutdown_function`).

Of course, if the shutdown functions are implemented *in* PHP, then the interrupt flag
will be checked while the VM is running PHP bytecode and the timeout will take effect.
But if the shutdown functions are built-in (implemented in C), it will not.

Since the shutdown functions are invoked through `zend_call_function`, add a check of the
`vm_interrupt` flag there. Then, the script time limit will be respected when *entering*
each shutdown function. The fact still remains that if a shutdown function is built-in and
runs for a long time, script execution will not time out until it finishes and the
interpreter tries to invoke the next one.

Still, the behavior of scripts with execution time limits will be more consistent after
this patch. To make the execution time-out feature work even more precisely, it would
be necessary to scrutinize all the built-in functions and add checks of the `vm_interrupt`
flag in any which can run for a long time. That might not be worth the effort, though.

It should be mentioned that this patch does not solely affect shutdown functions, neither
does it solely allow for interruption of running code due to script execution timeout.
Anything else which causes `vm_interrupt` to be set, such as the PHP interpreter receiving
a signal, will take effect when exiting from an internal function. And not just internal
functions which are called because they were registered to run at shutdown; there are
other cases where a series of internal functions might run in the midst of a script. In
all such cases, it will be possible to interrupt the interpreter now.

Closes GH-5543.
2020-05-13 12:47:12 +02:00
Alex Dowad
f0960879e4 zend_timeout is not a signal handler function
The 'int dummy' parameter to this function makes it appear that it was intended as a
signal handler, but it is not being used as such. So remove the redundant parameter.
2020-05-12 17:13:46 +02:00
Nikita Popov
5d93eab620 Don't reset SIGG(running) when calling zend_on_timeout
This is only an internal callback nowadays and does not actually
run any user code. It must be async signal safe.
2020-05-11 15:05:01 +02:00
Nikita Popov
718e55c3e0 Add zend_array_release() function
To complement zend_string_release() and zend_object_release().
2020-05-06 11:27:20 +02:00
Nikita Popov
48a34bc120 Add helper APIs for get_gc implementations
get_gc() implementations that need to explore heterogeneous data
currently work by computing how many GC entries they need,
allocating a buffer for that and storing it on the object. This
is inefficient and wastes memory, because the buffer is retained
after the GC run.

This commit adds an API for a single global GC buffer, which can
be reused by get_gc implementations (as only one get_gc call is
ever active at the same time). The GC buffer will automatically
grow during the GC run and be discarded at the end.
2020-04-27 10:48:22 +02:00
George Peter Banyard
446724bcd9 Fix [-Werror=missing-braces] compiler warning
Partial fix to bug 79431
2020-04-13 23:03:31 +02:00
Máté Kocsis
960318ed95
Change argument error message format
Closes GH-5211
2020-02-26 15:00:08 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00
Nikita Popov
cb7b21009b Merge branch 'PHP-7.4'
* PHP-7.4:
  Reset trampoline on executor startup
  Fix UAF in is_callable() and allocated trampoline
2020-01-30 11:05:56 +01:00
Nikita Popov
98deece6f7 Reset trampoline on executor startup
Make sure the trampoline is usable, even if we had an unclean
shutdown on the last request.
2020-01-30 11:05:04 +01:00
Nikita Popov
0a2f6c5527 Move undefined constant error into get_constant_ex
All the other error conditions are already handled in there, so
this one should be as well.
2020-01-10 11:48:10 +01:00
Nikita Popov
72a5fdec2c Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78921
2019-12-13 16:38:42 +01:00
Nikita Popov
7e9e0937f3 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #78921
2019-12-13 16:38:24 +01:00
Nikita Popov
621598eaa8 Fixed bug #78921
By resetting fake_scope during autoloading. We already do the same
when executing destructors.
2019-12-13 16:37:20 +01:00
Nikita Popov
065d00f241 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix leak with cycle in static prop of internal class
2019-10-21 10:27:35 +02:00
Nikita Popov
ed31e04133 Fix leak with cycle in static prop of internal class
More the cleanup of interned classes before the final GC run,
just like it is done for user classes.
2019-10-21 10:26:10 +02:00
Nikita Popov
edace5f5e0 Merge branch 'PHP-7.4' 2019-10-01 13:05:12 +02:00
Nikita Popov
f2e8851245 Remove func copy optimization for private method with static vars
Not NULLing the static_variables pointer for shadow methods during
static var shutdown would be a way to avoid this leak, but unless
there's evidence that inherited private methods with static vars are
actually a common use-case, I don't think we should keep this kind
of fragile edge-case optimization.

Fixes OSS-Fuzz #17875.
2019-10-01 13:04:06 +02:00
Nikita Popov
f61f122b9a Merge branch 'PHP-7.4' 2019-09-12 16:41:45 +02:00
Nikita Popov
4b9ebd837b Allow throwing exception while loading parent class
This is a fix for symfony/symfony#32995.

The behavior is:

* Throwing exception when loading parent/interface is allowed
  (and we will also throw one if the class is simply not found).
* If this happens, the bucket key for the class is reset, so
  it's possibly to try registering the same class again.
* However, if the class has already been used due to a variance
  obligation, the exception is upgraded to a fatal error, as we
  cannot safely unregister the class stub anymore.
2019-09-12 16:41:18 +02:00
Nikita Popov
403396e42c Merge branch 'PHP-7.4' 2019-09-11 16:30:59 +02:00
Nikita Popov
270e5e3c5b Only allow "nearly linked" classes for parent/interface
The requirements for parent/interface are difference than for the
variance checks in type declarations. The latter can work on fully
unlinked classes, but the former need inheritance to be essentially
finished, only variance checks may still be outstanding.

Adding a new flag for this because we have lots of space, but we
could also represent these "inheritance states" more compactly in
the future.
2019-09-11 16:27:28 +02:00
Nikita Popov
ad661375e8 Merge branch 'PHP-7.4' 2019-08-28 17:36:31 +02:00
Nikita Popov
f912445eb2 Add missed mutability check 2019-08-28 17:35:25 +02:00