Commit Graph

16016 Commits

Author SHA1 Message Date
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
Nikita Popov
6556846754 Fixed bug #79818
Only destroy the variable directly before reassigning it. The
value could be read in the meantime.
2020-07-10 14:36:50 +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
Ilija Tovilo
9fa1d13301
Implement match expression
RFC: https://wiki.php.net/rfc/match_expression_v2

Closes GH-5371.
2020-07-09 23:52:17 +02:00
George Peter Banyard
9839752a9c Voidify some ZEND_API functions
Closes GH-5805
2020-07-09 14:15:57 +02:00
Nikita Popov
613a56d1cb Remove FREE_UNFETCHED concept
In master normal FREE_OPs work like FREE_UNFETCHED_OP used to, so
there is no point in keeping this distinction anymore, it's just
confusing.
2020-07-09 11:58:33 +02:00
Nikita Popov
c05bfa362b Merge branch 'PHP-7.4'
* PHP-7.4:
  Switch back to FREE_UNFETCHED_OP_DATA
2020-07-09 11:54:44 +02:00
Nikita Popov
8318379dd3 Switch back to FREE_UNFETCHED_OP_DATA
Some of the code paths leading to this do not fetch op data.
Hopefully this fixes the release build failure.
2020-07-09 11:54:08 +02:00
Nikita Popov
04b17217b4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #79599 in a different way
  Revert "Fixed bug #97599 (coredump in set_error_handler)"
2020-07-09 11:18:03 +02:00
Nikita Popov
5795dfda93 Fix bug #79599 in a different way
Move the emission of the undefined variable notice before the
array separation.
2020-07-09 11:12:44 +02:00
Nikita Popov
a3cb612243 Revert "Fixed bug #97599 (coredump in set_error_handler)"
This reverts commit ccd41e0833.

This causes a large performance regression when notices are thrown
and large arrays are in scope, see bug #79794.
2020-07-09 11:12:44 +02:00
Derick Rethans
fc7650944a Merge branch 'PHP-7.4' 2020-07-09 09:51:15 +01:00
Derick Rethans
972383fda4 Revert "Partial fixed bug #79649 (Altering disable_functions from module init corrupts memory)"
This reverts commit a297c09da5.
2020-07-09 09:50:25 +01:00
George Peter Banyard
7ac9e9bf64 Use ZPP callable check in zend built in functions 2020-07-08 19:38:46 +02:00
Nikita Popov
2af1d36bc5 Skip special function optimization for redeclared disabled functions
As pointed out on GH-5817.
2020-07-08 10:11:00 +02:00
Nikita Popov
e45f7053cf Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79793
2020-07-07 16:33:06 +02:00
Nikita Popov
77acc8a069 Fixed bug #79793
Make sure the string key is not released while throwing the
undefined index warning.
2020-07-07 16:29:48 +02:00
Nikita Popov
beb002a867 Fixed bug #79791
First throw the undefined variable warning, and then set the
variable to null. Otherwise we're not guaranteed that it's
actually null afterwards.
2020-07-07 16:00:50 +02:00
Nikita Popov
cdc4ea2a5c JIT support for undefined index/offset handling 2020-07-07 15:13:03 +02:00
Nikita Popov
f497b69944 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79784
2020-07-07 14:24:39 +02:00
Nikita Popov
62bec0e083 Fixed bug #79784
The fix here is essentially the same as for bug #78598, just for
the undefined variable notice, rather than the undefined index one.
2020-07-07 14:22:58 +02:00
Nikita Popov
2c73bf7e3f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78598
2020-07-07 12:28:35 +02:00
Nikita Popov
220880ad2d Fixed bug #78598
When performing an RW modification of an array offset, the undefined
offset warning may call an error handler / OB callback, which may
destroy the array we're supposed to change. Detect this by temporarily
incrementing the reference count. If we find that the array has been
modified/destroyed in the meantime, we do nothing -- the execution
model here would be that the modification has happened on the destroyed
version of the array.
2020-07-07 12:13:58 +02:00
Nikita Popov
ecf368b8f2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79792
2020-07-07 12:00:34 +02:00
Nikita Popov
48a247178e Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79792
2020-07-07 11:59:40 +02:00
Nikita Popov
64931fd3c4 Fixed bug #79792
We need to remove the iterators even if the array is empty (we
will not create one if the first place, but the array may become
empty after the fact).
2020-07-07 11:58:25 +02:00
Nikita Popov
b48bd671b8 Assert no exception if using NEXT_OPCODE()
When NEXT_OPCODE() is used instead of NEXT_OPCODE_CHECK_EXCEPTION(),
assert that there is indeed no exception.
2020-07-07 11:34:43 +02:00
Nikita Popov
5d0687e895 Assert exception set in HANDLE_EXCEPTION()
Some code paths were checking this manually, but we can turn this
into a general assertion to avoid surprises (functions returning
failure without throwing).
2020-07-07 11:31:05 +02:00
Nikita Popov
fb91611276 Remove #undefs from vm_gen
Possibly these were needed for VM_EXPORT, but they don't serve a
purpose now.
2020-07-07 11:25:28 +02:00
Nikita Popov
002c264d07 Remove ZEND_VM_EXPORT functionality
This hasn't been used since forever and makes things more confusing
than they already are.
2020-07-07 11:23:28 +02:00
Nikita Popov
eaf6303a74 Fixed bug #79790
I haven't tracked down in detail where the interaction with
increment_function comes from, but the root problem here is failure
to handle the illegal offset type exception.
2020-07-07 10:56:55 +02:00
Nikita Popov
e0743d0f91 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79779
2020-07-07 10:27:53 +02:00
Nikita Popov
6a9d934b2c Fixed bug #79779
ASSIGN_OBJ_REF was not handling in zend_wrong_string_offset.
2020-07-07 10:27:22 +02:00
Nikita Popov
7da8c48a9b Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79778
2020-07-07 10:20:31 +02:00
Nikita Popov
d9b4974cbc Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79778
2020-07-07 10:20:11 +02:00
Nikita Popov
b765f96f5f Fixed bug #79778
In the interest of avoiding side-effects during dumping, I'm
replacing the value with a <constant ast> string instead of
performing an update constant operation.
2020-07-07 10:19:39 +02:00
Nikita Popov
1e39469678 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79783
2020-07-07 09:57:07 +02:00
Nikita Popov
971e5c5186 Fixed bug #79783
Make sure we don't drop the by-reference check when passing the
result of a VM builtin function.
2020-07-07 09:56:14 +02:00
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +02:00
Nikita Popov
5b4bf4d3e9 Fixup test 2020-07-07 09:23:05 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +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
moliata
4a0d6901bb refactor: class constants parsing
As part of my work on typed class constants, I wanted to make a
separate pull request for unrelated changes.

These include:

 * Moving from ast->child[0]->attr to ast->attr
 * Making zend_ast_export_ex() export class constants' visibility
 * Extracting an additional zend_compile_class_const_group() function

Closes GH-5812.
2020-07-06 18:34:41 +02:00
Máté Kocsis
b18b2c8fe5
Add string or object ZPP macros
Closes GH-5788
2020-07-06 12:42:02 +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
49396f817a Fixed bug #79777 2020-07-04 09:59:42 +02:00
Nikita Popov
6a195cacf3 Treat attribute argument lists like normal argument lists
Allow trailing comma. Syntactically allow unpacking, but forbid it
during compilation.

The trailing comma test-case is adopted from GH-5796.
2020-07-02 15:27:45 +02:00
codinghuang
5ea28fe6c4
Use correct ZPP mechanism in get_class_methods()
From now on, instead of returning null, an exception is thrown when
not a string or an object is passed to the function.

Closes GH-5792
2020-07-02 11:40:05 +02:00
Nikita Popov
271bc689ea Add iterator get_gc function for generators
Closes GH-5787.
2020-07-01 15:17:26 +02:00
Nikita Popov
312201dce4 Add get_gc handle for object iterators
Optional handler with the same semantics as the object handler.
2020-07-01 15:17:22 +02:00
Nikita Popov
89b2483edd Remove generator iterator member
This is probably a leftover from the PHP 5 implementation, where
the iterator was embedded directly in the generator.
2020-06-30 18:26:29 +02:00
Nikita Popov
af4ff75c98 Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove bogus generator iterator dtor
2020-06-30 17:33:51 +02:00
Nikita Popov
d1be10dd7e Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Remove bogus generator iterator dtor
2020-06-30 17:33:33 +02:00
Nikita Popov
187a72d563 Remove bogus generator iterator dtor
Fixes a use-after-free encountered in Symfony's SecurityBundle.
I don't have a reproducer for this, and believe the issue can only
occur if we leak an iterator (the leak is a separate issue).

We should not free the generator iterator here, because we do not
own it. The code that fetched the iterator is responsible for
releasing it. In the rare case where we do hit this code-path,
we cause a use-after-free.
2020-06-30 17:32:42 +02:00
Máté Kocsis
30067894fc
Update outdated arginfo hashes 2020-06-30 16:02:11 +02:00
Nikita Popov
917e28d77e Assume offsetof() exists
This is a standard C macro. Define XtOffsetOf as an alias for
compatibility, as this is the name we use in most code right now.
2020-06-30 15:55:50 +02:00
Nikita Popov
c5e8c9865e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix leak when setting cyclic previous exception in finally
2020-06-30 12:26:03 +02:00
Nikita Popov
0fa70b3cde Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix leak when setting cyclic previous exception in finally
2020-06-30 12:25:29 +02:00
Nikita Popov
fc6f53d426 Fix leak when setting cyclic previous exception in finally
A curious exception handling pattern found in Symfony's HttpClient.
2020-06-30 12:24:32 +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
Fabien Villepinte
0c6d06ecfa Replace EXPECTF when possible
Closes GH-5779
2020-06-29 21:31:44 +02:00
Dmitry Stogov
24a8065f8b Tracing JIT support for include() and generators 2020-06-29 21:40:49 +03: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
Martin Schröder
053ef28b8d Implement Attribute Amendments.
RFC: https://wiki.php.net/rfc/attribute_amendments

Support for attribute grouping is left out, because the short
attribute syntax RFC will likely make it obsolete.

Closes GH-5751.
2020-06-29 10:45:51 +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
c5caa05171 Fixed bug #79740 2020-06-26 10:31:55 +02:00
Ayesh Karunaratne
d114812faf [ci skip] Various typo fixes in stub comments and CHANGES file 2020-06-25 23:32:40 +02:00
Nikita Popov
47cf18ba4e Don't include trailing newline in comment token
Don't include a trailing newline in T_COMMENT tokens, instead leave
it for a following T_WHITESPACE token. The newline does not belong
to the comment logically, and this makes for an ugly special case,
as other tokens do not include trailing newlines.

Whitespace-sensitive tooling will want to either forward or backward
emulate this change.

Closes GH-5182.
2020-06-25 11:25:22 +02:00
Nikita Popov
e12b9df05d Make sorting stable
Make user-exposed sorts stable, by storing the position of elements
in the original array, and using those positions as a fallback
comparison criterion. The base sort is still hybrid q/insert.

The use of true/false comparison functions is deprecated (but still
supported) and should be replaced by -1/0/1 comparison functions,
driven by the <=> operator.

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

Closes GH-5236.
2020-06-25 10:49:34 +02:00
Nikita Popov
f37138d2c5 Don't use iterator_funcs_ptr if it is null
This avoids ubsan warnings. Alternatively we could always initialize
iterator_funcs_ptr for aggregates, instead of doing so only for
non-internal ones.
2020-06-25 10:30:40 +02:00
Nikita Popov
ff19ec2df3 Introduce InternalIterator
Userland classes that implement Traversable must do so either
through Iterator or IteratorAggregate. The same requirement does
not exist for internal classes: They can implement the internal
get_iterator mechanism, without exposing either the Iterator or
IteratorAggregate APIs. This makes them usable in get_iterator(),
but incompatible with any Iterator based APIs.

A lot of internal classes do this, because exposing the userland
APIs is simply a lot of work. This patch alleviates this issue by
providing a generic InternalIterator class, which acts as an
adapater between get_iterator and Iterator, and can be easily
used by many internal classes. At the same time, we extend the
requirement that Traversable implies Iterator or IteratorAggregate
to internal classes as well.

Closes GH-5216.
2020-06-24 15:31:41 +02:00
Máté Kocsis
b5c7a83dca
Remove unnecessary PHPDoc-alike blocks from tests
Closes GH-5759
2020-06-24 13:13:44 +02:00
Nikita Popov
653e4ea1c5 Add flag to forbid dynamic property creation on internal classes
While performing resource -> object migrations, we're adding
defensive classes that are final, non-serializable and non-clonable
(unless they are, of course). This path adds a ZEND_ACC_NO_DYNAMIC_PROPERTIES
flag, that also forbids the creation of dynamic properties on these objects.
This is a subset of #3931 and targeted at internal usage only
(though may be extended to userland at some point in the future).

It's already possible to achieve this (what the removed
WeakRef/WeakMap code does), but there's some caveats: First, this
simple approach is only possible if the class has no declared
properties, otherwise it's necessary to special-case those
properties. Second, it's easy to make it overly strict, e.g. by
forbidding isset($obj->prop) as well. And finally, it requires a
lot of boilerplate code for each class.

Closes GH-5572.
2020-06-24 11:52:36 +02:00
Nikita Popov
59c4c8297b Add test case for previous commit
Forgot to "git add".
2020-06-24 10:51:51 +02:00
Nikita Popov
c9b9f525a9 Include stub hash in generated arginfo files
The hash is used to check whether the arginfo file needs to be
regenerated. PHP-Parser will only be downloaded if this is actually
necessary.

This ensures that release artifacts will never try to regenerate
stubs and thus fetch PHP-Parser, as long as you do not modify any
files.

Closes GH-5739.
2020-06-24 09:55:19 +02:00
Christoph M. Becker
91982bad63 7.3 is now 7.3.21-dev 2020-06-23 10:29:42 +02:00
Derick Rethans
56ab608463 Consistent file naming. 2020-06-22 15:32:52 +01:00
Dmitry Stogov
ea2b0d3c8b Fixed JIT failures on Windows 2020-06-22 14:57:04 +03:00
Christoph M. Becker
6bc375f40a Mark failing tests as XFAIL for now
These test fail on Window since some recent changes to JIT; we mark
them as XFAIL until the issues are resolved.
2020-06-20 11:07:57 +02:00
Alex Dowad
7e2147be23 Clean up some unused code (and fix some comments) in build scripts
- Fix typo in build/php.m4

- Nothing uses HAVE_INTTYPES_H; so remove check for header file

- Nothing defines ZEND_ACCONFIG_H_NO_C_PROTOS; so remove #ifndef

- `format_money` was removed in 2019, so <monetary.h> no longer needed

- Nothing uses HAVE_NETDB_H; so remove check for header file

- Nothing checks HAVE_TERMIOS_H; so remove check for header file

    (This was actually added when Wez Furlong was adding the original implementation of
    PTY support in `proc_open`, since replaced.)

- Nothing checks HAVE_SYS_AUXV_H; so remove check for header file

- PHP_BUILD_DATE variable is not used for anything, so remove it

    This variable was added to the Makefile, but from there, was not used for anything.
    The comments suggest it was intended to allow 'reproducible builds'. Presumably,
    this means that if a bug is found in a PHP binary somewhere, one could look at the
    Makefile which it was built from, see the date, and then could check the same
    code version out from source control. But... there can easily be multiple commits
    to the repo in the same day. Also, what makes us think that the Makefile which a
    binary was built from will be easily available?

    Besides, ext/standard/info.c already embeds the build date and time in each binary...
    but it does it using `__DATE__` and `__TIME__` (see `php_print_info`).

- Nothing checks HAVE_FINITE; so don't check for function

- Grammar fix to comment in build/php.m4

- Nothing sets $php_ldflags_add_usr_lib variable in configure, so remove conditional

    This was added in 2002, when Rasmus was having difficulty building PHP on some
    host and needed to have /usr/lib in the rpath. It was never documented and
    probably has never been used by anyone else.
2020-06-19 22:04:52 +02:00
Nikita Popov
5571765609 Forbid use of <?= as a semi-reserved identifier
One of the weirdest pieces of PHP code I've ever seen. In terms
of tokens, this gets internally translated to

    use x as y; echo as my_echo;

On master it crashes because this "echo" does not have attached
identifier metadata. Make sure it is added and then reject the
use of "<?=" as an identifier inside zend_lex_tstring.

Fixes oss-fuzz #23547.
2020-06-19 09:29:58 +02:00
Dmitry Stogov
6fa126e966 MAY_BE_INDIRECT inference 2020-06-18 18:54:32 +03:00
moliata
48e16a9dba Use ZEND_TOSTRING_FUNC_NAME
Closes GH-5736.
2020-06-18 17:06:19 +02:00
Nikita Popov
6cf5162480 Merge branch 'PHP-7.4' 2020-06-18 10:16:47 +02:00
Nikita Popov
3dfa25833f Don't use ternary in ini default
We use sizeof() on ini defaults, so this isn't safe. I can't reproduce
the failures locally, but I expect this to fix the asan jobs.
2020-06-18 10:15:53 +02:00
Alex Dowad
3a19726bce Remove unneeded --disable-inline-optimization build parameter
In 1999, inline optimization was turned off by default. The commit log indicates this was
done because GCC was running out of memory on some hosts when building the Zend executor.
In 2003, inline optimization was re-enabled by default, but a build option was added to
turn it off if one runs out of memory when building.

Computing hardware has come a long way since 2003 and I doubt that anyone is running out
of memory when building PHP now.

Interestingly, this code set an unused variable called `INLINE_CFLAGS`. It actually
disabled inline optimization by adding -O0 to the build command, not using `INLINE_CFLAGS`.

Just to see how much memory GCC/Make are using when building PHP, I tried building with
successively higher values of `ulimit -v` until it succeeded. Interestingly, while most
of the codebase can be built with about 400MB of memory, ext/fileinfo/libmagic/apprentice.c
requires 1.2GB, doubtless because it includes ext/fileinfo/data_file.c, which is more
than 350,000 lines long. That is with GCC 7.5.0.

Most users get PHP as a binary package anyways, so the question is, are *packagers*
of PHP trying to build on machines with just 1GB RAM? And would they want to package
a PHP interpreter built with *no optimizations*? I can't imagine either being true.
2020-06-17 19:31:35 +02:00
Nikita Popov
4f260411d1 Merge branch 'PHP-7.4' 2020-06-17 17:14:05 +02:00
Nikita Popov
9b3e57921f Suppress zend signals check in two readline tests
Installing a callback handler may cause libedit to register new
signals during the request.
2020-06-17 17:13:01 +02:00
moliata
45d1c38dab Use zend_is_constructor() 2020-06-17 16:46:17 +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
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce
`ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)`
to mark unreachable code does no longer trigger C4715[1] warnings in
debug builds.  This may be useful for other compilers as well.

[1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
2020-06-16 18:39:09 +02:00
Dmitry Stogov
bb3d4456ee Change GC_COLLECTABLE flag into GC_NOT_COLLECTABLE to simplify GC_MAY_LEAK() check 2020-06-15 14:26:22 +03:00
Nikita Popov
50c87e92fc Use GC stack in nested data removal
We should be doing this anyway to prevent stack overflow, but on
master this is important for an additional reason: The temporary
GC buffer provided for get_gc handlers may get reused if the scan
is performed recursively instead of indirected via the GC stack.

This fixes oss-fuzz #23350.
2020-06-12 15:02:12 +02:00
Nikita Popov
c7ad8a8738 Initialize indentation_uses_spaces field
This avoids reading a trap representation from _Bool,
but shouldn't matter as far as behavior is concerned.
2020-06-12 11:23:48 +02:00
Nikita Popov
4a7ec516e0 Move label to correct position 2020-06-12 10:44:37 +02:00
Nikita Popov
0949214ab3 Fix null pointer UB in GC
This is just plain stupid: In C, it is not permitted to add zero
to a null pointer. In C++, it is permitted.
2020-06-12 10:33:39 +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
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
c23edd2acf Remove called_scope inheritance in zend_call_method()
Similar to 097043db2a, but for the
zend_call_method() API. I don't think we ever use this for
static methods, but this logic shouldn't be there. If you want
to inherit the active LSB scope for some reason, do so explicitly.
2020-06-10 10:04:37 +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
Christoph M. Becker
68dd6cc92b Control VCRT leak reporting via environment variable in debug builds
Formerly, this had to be enabled by passing the configuration flag
`--enable-crt-debug`; now it can be enabled by setting the environment
variable `PHP_WIN32_DEBUG_HEAP`.  The advantage is that it is no longer
necessary to do separate builds, at the cost of a very minor
performance penalty during process startup.
2020-06-10 09:05:17 +02:00
Xinchen Hui
28b4761ecb Merge branch 'PHP-7.4'
* PHP-7.4:
  Partial fixed bug #79649 (Altering disable_functions from module init corrupts memory)
2020-06-10 11:21:13 +08:00
Xinchen Hui
a297c09da5 Partial fixed bug #79649 (Altering disable_functions from module init corrupts memory)
In module startup stage, we should not initiliaze
EG(modified_ini_directives) as it use zend MM, the zend MM will be
restart at the end of modules startup stage,

by say "partial", because this issue still exists if altering ZEND_USER
inis, we should add a zend_ini_deactive at the end of modules startup
stage, but it brings some new cost, and I think no one would do things
like that
2020-06-10 11:16:42 +08:00
Dmitry Stogov
a60cdcf084 A helper to trace executed source lines 2020-06-10 00:13:39 +03: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
Nikita Popov
bcada03f48 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79683
2020-06-09 15:52:48 +02:00
Nikita Popov
2447fd9f84 Fixed bug #79683
Reset fake_scope during __toString() call.

I'll check if we can solve this more globally in master, by
resetting fake_scope in zend_call_function.
2020-06-09 15:51:05 +02:00
George Peter Banyard
4b77a158ef Use standard boolean type as zend_bool typedef
Closes GH-5624
2020-06-09 11:43:45 +02:00
George Peter Banyard
9fbc31704d Fix incorrect usage of zend_bool in Zend globals 2020-06-09 11:43:37 +02:00
Nikita Popov
be540b35d2 Remove some special-casing in zend_call_method()
Don't treat the !fn_proxy && !obj_ce case differently. There doesn't
seem to be any need for it, and it will result in subtly different
behavior (e.g. it will accept "Foo::bar" syntax, but break as soon
as you pass in an fn_proxy cache).
2020-06-09 10:10:58 +02:00
Ilija Tovilo
2a3ac4a8e7 Add missing terminators in zend_language_parser.y
Closes GH-5688
2020-06-09 00:44:13 +02:00
twosee
05ed7bff17 Make zend_argument_error_variadic static
Closes GH-5687
2020-06-09 00:42:48 +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
Nikita Popov
3d4f79d678 Don't allow variables as attribute name
Attributes require a static class name...

This fixes https://oss-fuzz.com/testcase-detail/6267052359942144.
2020-06-08 14:34:43 +02:00
Nikita Popov
b03cafd19c Fix bug #77966: Cannot alias a method named "namespace"
This is a bit tricky: In this cases we have "namespace as", which
means that we will only recognize "namespace" as an identifier when
the lookahead token is already at the "as". This means that
zend_lex_tstring picks up the wrong identifier.

We solve this by actually assigning the identifier as the semantic
value on the parser stack -- as in almost all cases we will not
actually need the identifier, this is just an (offset, size)
reference, not a copy of the string.

Additionally, we need to teach the lexer feedback mechanism used
by tokenizer TOKEN_PARSE mode to apply feedback to something
other than the very last token. To that purpose we pass through
the token text and check the tokens in reverse order to find the
right one.

Closes GH-5668.
2020-06-08 12:55:14 +02:00
Nikita Popov
57f408e87c Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79657
2020-06-08 11:32:24 +02:00
Nikita Popov
df2db7fcea Fixed bug #79657
Throwing an exception should count as an initialization for this
purpose.
2020-06-08 11:31:28 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00