Commit graph

1603 commits

Author SHA1 Message Date
Máté Kocsis
debd38f851 Add support for sensitive parameters in stubs 2022-06-04 18:15:05 +02:00
Máté Kocsis
14da1cb909
Add support for class constants in stubs (#7434) 2022-05-22 22:27:23 +02:00
George Peter Banyard
5171cb435a Fix [-Wundef] warnings in standard extension 2022-04-01 15:48:41 +01:00
Nikita Popov
e32642c541 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix bug #81598: Use C.UTF-8 as LC_CTYPE locale by default
2021-12-05 21:04:10 +01:00
Nikita Popov
26e424465c Fix bug #81598: Use C.UTF-8 as LC_CTYPE locale by default
Unfortunately, libedit is locale based and does not accept UTF-8
input when the C locale is used. This patch switches the default
locale to C.UTF-8 instead (if it is available). This makes libedit
work and I believe it shouldn't affect behavior of single-byte
locale-dependent functions that PHP otherwise uses.

Closes GH-7635.
2021-12-05 21:03:27 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
fabcc9a350 Fix long-term shutdown/tick fci/fcc storage
Normally incrementing the refcount on just function_name is
sufficient. However, if the callable is of the form 'X::y' inside
an instance method, this will capture $this in fcc.object, which
also needs to be retained.

The fci_addref/fci_release helpers should likely be exported as
a general API, as we may have this problem in other places as
well.

Fixes oss-fuzz #39778.
2021-10-11 12:19:29 +02:00
Nikita Popov
51a504c8be Avoid string copy in get_cfg_var()
basic_functions.c already has a macro for returning an ini
value to userland, so make use of it for get_cfg_var() as well,
after generalizing it to not write to return_value in particular.
2021-08-27 15:34:46 +02:00
Nikita Popov
ef5558a8cd
Use zend_string for putenv key (#7379)
A zend_string will be created anyway for the hash key,
so we may as well create one in the first place.
2021-08-17 12:29:04 +02:00
Nikita Popov
b56699b8f0 Use system allocator for putenv value
The putenv value is stored in environ. If for some reason we
fail to restore it on shutdown, make sure that we fail gracefully
by using a system allocated value, rather than a ZMM allocated one.

This is an additional mitigation for bug #81316 style issues if
all else fails.
2021-08-17 11:03:14 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
George Peter Banyard
e7135cb817
Use zend_string_equals_* API in a couple of more place
Closes GH-6979
2021-05-14 13:45:17 +01:00
Nikita Popov
4f46bec5d4 Initialize zpp varargs variables
These are not initialized if no args are passed.
2021-05-10 19:19:26 +02:00
Aaron Piotrowski
39fa55a4c9
Switch register_tick_function back to zend_parse_parameters
No reason to use fast ZPP in register_tick_function, so let’s keep the binary size down just a bit.
2021-05-10 10:17:29 -05:00
George Peter Banyard
a9695cc615
Refactor register shutdown function mechanism
Use FCI/FCC structure instead of custom implementation which does the same.
This also fixes the "bug" which prevented static methods from being shutdown functions.

Closes GH-5829

Co-authored-by: Aaron Piotrowski <aaron@trowski.com>
2021-05-10 15:54:59 +01:00
Aaron Piotrowski
66bfad57de
Remove unnecessay NULL
Z_PARAM_FUNC already sets params to NULL.
2021-05-09 14:55:05 -05:00
Aaron Piotrowski
0189585c9e
Fix tick function with arguments
Tick function arguments need to be copied to fci params.
2021-05-09 14:08:20 -05:00
Aaron Piotrowski
7ec048f96d
Do not free tick function entry
This memory is freed by zend_llist.
2021-05-09 11:44:32 -05:00
George Peter Banyard
05e6f3ebde
Refactor register_tick_function mechanism (#5828) 2021-05-08 10:09:09 +01:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Nikita Popov
dc7030300c Use interned strings for error_get_last()
We have known strings for all the array keys, use them.
2021-04-23 11:05:14 +02:00
Nikita Popov
b66eb866c9 Convert last_error_file to zend_string 2021-04-23 11:05:14 +02:00
Nikita Popov
4ce5d2ea88 Add known strings for jit autoglobals
We always create interned strings for all autoglobals anyway, so
we might as well add known strings to make them more widely usable.
2021-04-09 15:37:59 +02:00
Dmitry Stogov
c732ab400a Change Zend Stream API to use zend_string* instead of char*.
This allows to eliminate re-calculation of string lenght and hash value.
See the detailed list of changes in UPGRADING.INTERNALS.
2021-03-16 20:31:36 +03:00
Máté Kocsis
4c6533c257
Generate class entries from stubs for com, standard, xmlreader, xmlwriter, xsl, zip, Zend
Closes GH-6706
2021-02-22 15:24:03 +01:00
Nikita Popov
070e24d7a9 Allow all scalar types in ini_set()
This changes ini_set() to accept all scalar types
(string|int|float|bool|null) for the new value. The idea here is
that while the INI system ultimately works with strings, its value
interpretation is designed to be consistent with PHP's casting rules,
e.g. "1" and "" are interpreted as boolean true and false respectively.

I personally believe that writing ini_set('precision', 10) makes more
sense than ini_set('precision', '10'), and find strict_types to be
unnecessarily pedantic here.

Closes GH-6680.
2021-02-11 15:01:16 +01:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
422d1665a2 Make convert_to_*_ex simple aliases of convert_to_*
Historically, the _ex variants separated the zval first, if a
conversion was necessary. This distinction no longer makes sense
since PHP 7.

The only difference that was still left is that _ex checked whether
the type is the same first, but the usage of these macros did not
actually distinguish on whether such an inlined check is valuable
or not in a given context.

Also drop the unused convert_to_explicit_type macros.
2021-01-14 12:11:11 +01:00
Nikita Popov
e69a65a2b5 Export php_getenv() API
This exports a php_getenv() API which will fetch an environment
variable in a thread-safe manner (assuming all other environment
manipulations are thread-safe ... ha ha ha).

Closes GH-6571.
2021-01-04 14:52:07 +01:00
Nikita Popov
3f0e94e3c7 Accept zend_string in highlight_string API 2020-10-22 14:35:40 +02:00
Nikita Popov
bcb5ae15e0 Merge branch 'PHP-8.0'
* PHP-8.0:
  Make highlight_string() accept string in zpp
2020-10-22 14:31:54 +02:00
Nikita Popov
db5979dfe2 Make highlight_string() accept string in zpp
To satisfy the type declaration.
2020-10-22 14:31:42 +02:00
Nikita Popov
9426c6e967 Don't use global for array_walk_fci
There's really no good reason for this to be a global, we can
easily pass it down to php_array_walk().
2020-10-19 15:33:03 +02:00
Christoph M. Becker
521c36c855 Remove IGNORE_URL_WIN macro
This macro is defined to zero as of PHP 5.0.0, and as the comment
indicates, is no longer relevant.  Thus, we remove the definition and
all usages from the core and bundled extensions.

Closes GH-6351.
2020-10-18 23:36:36 +02:00
Nikita Popov
8067cf4752 Use callable type in register_shutdown_function()
To make things a bit less weird, split off the function name into
a zval stored separately from the arguments. This allows us to
use normal zpp and get standard behavior.
2020-09-25 14:48:33 +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
Máté Kocsis
2c96780e1c
Fix UNKNOWN default values in ext/standard
Closes GH-6026
2020-09-07 18:58:11 +02:00
George Peter Banyard
4a438b4469 Warning to Error promotion in ext/standard
Those should be the last ones other than set(raw)cookie()

Closes GH-5814
2020-09-03 17:43:57 +02: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
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
1d0f55315e Store incomplete_class entry as normal global
I don't see any reason why this needs to live in a thread-safe
global, unlikely all other class entries.
2020-08-28 09:57:54 +02:00
Nikita Popov
ce83ec8790 Clean up strtok implementation
Store the zend_string instead of performing a copy and storing
in a zval. Also make sure the string is released immediately if
it's no longer needed. Finally, avoid null pointer offset UB if
no string has been set -- though I'm wondering if this case
shouldn't be generating a warning?
2020-08-27 12:24:58 +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
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
be9c5daf28 Remove null from highlight_* return types
Also fix show_source() discrepancy in func_info.
2020-07-21 10:40: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
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Christoph M. Becker
2a28589c7d Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix potential environment variable deadlock
2020-06-24 11:44:47 +02:00
Christoph M. Becker
32257ac17f Fix potential environment variable deadlock
We have to unlock the environment before bailing out.
2020-06-24 11:44:07 +02:00
Christoph M. Becker
408961987f Fix typos 2020-06-17 16:45:12 +02:00