Commit Graph

632 Commits

Author SHA1 Message Date
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
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
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
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
Levi Morrison
94fd52dd09 Add Z_PARAM_ITERABLE and co 2020-09-03 07:03:12 -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
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
670036e2a9 Use Z_PARAM_CLASS in PDOStatement::fetchObject()
Instead of implementing custom logic.
2020-08-13 16:20:29 +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
7991fc2753 Accept zend_object in zend_read_property 2020-08-07 16:40:27 +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
993be4b9bf Fix STR_OR_OBJ_OF_TYPE stringable handling 2020-07-29 11:29:49 +02:00
Nikita Popov
1f8a93abaa Support class+mask union for internal argument 2020-07-24 16:40:14 +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
twosee
a65ec4c2db Change type of max_num_args to uint32_t
Closes GH-5885.
2020-07-23 00:55:58 +08:00
Nikita Popov
7fd4212cc0 Add common code for magic method assignment
This was repeated three times.
2020-07-20 14:57:10 +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
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
twosee
b284ba3943 Add zend_wrong_parameter_error to reduce the size of ZPP macro
Closes GH-5831.
2020-07-10 10:12:23 +02:00
George Peter Banyard
9839752a9c Voidify some ZEND_API functions
Closes GH-5805
2020-07-09 14:15:57 +02:00
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +02:00
Nikita Popov
0280b83e11 Avoid some unnecessary uses of no_separation=0
For the rare cases where references are part of the API,
construct them explicitly. Otherwise do not allow separation.
2020-07-06 19:05:57 +02:00
Máté Kocsis
b18b2c8fe5
Add string or object ZPP macros
Closes GH-5788
2020-07-06 12:42:02 +02:00
Máté Kocsis
e93d20ad7e
Add ZPP macros for class name or object parameters
Closes GH-5647
2020-06-30 11:19:30 +02:00
Nikita Popov
1314ccbf8c Cache __unserialize() instead of unserialize()
We should use these cache slots for the new object serialization
mechanism rather than the old one.
2020-06-26 10:54:40 +02:00
Nikita Popov
15846ff115 Add ZVAL_OBJ_COPY macro
For the common ZVAL_OBJ + GC_ADDREF pattern.
This mirrors the existing ZVAL_STR_COPY API.
2020-06-17 16:36:56 +02:00
Nikita Popov
1386850838 Use unused attribute for _dummy
The (void)_dummy is apparently considered a read of an uninitialized
variable. As it is a _Bool now, which has trap representations, this
is no longer considered legal and results in somewhat odd ubsan
warnings of the form:

runtime error: load of value 0, which is not a valid value for type 'zend_bool' (aka 'bool')
2020-06-12 10:18:19 +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
twosee
83a77015ad Add helper APIs for maybe-interned string creation
Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using
ZVAL_INTERNED_STRING and ZSTR_CHAR.

Add zend_string_init_fast() as a helper for the empty string /
one char interned string / zend_string_init() pattern.

Also add corresponding ZVAL_STRINGL_FAST etc macros.

Closes GH-5684.
2020-06-08 15:31:52 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00
Benjamin Eberlei
a7908c2d11 Add Attributes
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-06-04 18:19:49 +02:00
George Peter Banyard
cebe750f46 Refactor ZPP API to use uint32_t as everywhere else
Closes GH-5609
2020-05-22 17:13:42 +02:00
Nikita Popov
50a9f511cc Allow null callback to array_filter()
With same behavior as not passing it.
2020-05-13 17:24:13 +02:00
Nikita Popov
3f51d82bca Rename zend_zval_get_type() API
We have a bunch of APIs for getting type names and it's sometimes
hard to keep them apart ... make it clear that this is the one
you definitely do not want to use.
2020-05-13 14:56:05 +02:00
George Peter Banyard
25acc4a6b4 Fix [-Wundef] warning in Zend folder 2020-05-12 22:01:51 +02:00
George Peter Banyard
4865592525 Remove old ARG_COUNT() macro
Use ZEND_NUM_ARGS() instead.

Clsoes GH-5551
2020-05-11 16:52:04 +02:00
Máté Kocsis
3ebce8e9fc
Fix UNKNOWN default values in various extensions
Closes GH-5514
2020-05-05 19:08:20 +02:00
George Peter Banyard
7b74fc7a7b Add Fast ZPP string|int type check 2020-05-02 19:50:51 +02:00
Máté Kocsis
ffcc8135e2
Convert UNKNOWN default values to null in ext/date
Closes GH-5509
2020-05-02 11:05:37 +02:00
Nikita Popov
53eee290b6 Completely remove disabled functions from function table
Currently, disabling a function only replaces the internal
function handler with one that throws a warning, and a few
places in the engine special-case such functions, such as
function_exists. This leaves us with a Schrödinger's function,
which both does not exist (function_exists returns false) and
does exist (you cannot define a function with the same name).
In particular, this prevents the implementation of robust
polyfills, as reported in https://bugs.php.net/bug.php?id=79382:

    if (!function_exists('getallheaders')) {
        function getallheaders(...) { ... }
    }

If getallheaders() is a disabled function, this code will break.

This patch changes disable_functions to remove the functions from
the function table completely. For all intents and purposes, it
will look like the function does not exist.

This also renders two bits of PHP functionality obsolete and thus
deprecated:

 * ReflectionFunction::isDisabled(), as it will no longer be
   possible to construct the ReflectionFunction of a disabled
   function in the first place.
 * get_defined_functions() with $exclude_disabled=false, as
   get_defined_functions() now never returns disabled functions.

Fixed bug #79382.

Closes GH-5473.
2020-04-30 09:53:57 +02:00
Nikita Popov
fd00c7cf10 Pass existing lcname to check_magic_method_implementation 2020-04-27 12:33:29 +02:00
Máté Kocsis
3fe49d81f8
Generate method entries from stubs for a couple of extensions
Closes GH-5368
2020-04-11 13:28:53 +02:00
Máté Kocsis
1d05771a70
Add support for generating method entries from stubs
Closes GH-5363
2020-04-11 09:15:14 +02:00
Nikita Popov
2d1bf6970d Add Z_PARAM_RESOURCE_OR_NULL()
As a more explicit alternative to Z_PARAM_RESOURCE_EX(, 1, 0).
2020-04-09 15:39:11 +02:00