Commit graph

119317 commits

Author SHA1 Message Date
Eddie Kohler
ada776c84c Make HashContexts serializable.
* Modify php_hash_ops to contain the algorithm name and
  serialize and unserialize methods.

* Implement __serialize and __unserialize magic methods on
  HashContext.

Note that serialized HashContexts are not necessarily portable
between PHP versions or from architecture to architecture.
(Most are, though Keccak and slow SHA3s are not.)

An exception is thrown when an unsupported serialization is
attempted.

Because of security concerns, HASH_HMAC contexts are not
currently serializable; attempting to serialize one throws
an exception.

Serialization exposes the state of HashContext memory, so ensure
that memory is zeroed before use by allocating it with a new
php_hash_alloc_context function. Performance impact is
negligible.

Some hash internal states have logical pointers into a buffer,
or sponge, that absorbs input provided in bytes rather than
chunks. The unserialize functions for these hash functions
must validate that the logical pointers are all within bounds,
lest future hash operations cause out-of-bounds memory accesses.

* Adler32, CRC32, FNV, joaat: simple state, no buffer positions
* Gost, MD2, SHA3, Snefru, Tiger, Whirlpool: buffer positions
  must be validated
* MD4, MD5, SHA1, SHA2, haval, ripemd: buffer positions encoded
  bitwise, forced to within bounds on use; no need to validate
2020-06-30 14:30:33 +02:00
Eddie Kohler
dc85be5456 Mark Keccak functions that contain expected misaligned accesses.
To avoid undefined behavior warnings for those accesses.
2020-06-30 14:26:48 +02:00
Eddie Kohler
ff69a8a789 Move __alignof__ support check into main configure.ac. 2020-06-30 14:26:48 +02:00
Eddie Kohler
1e9ff7e757 SHA-3 Keccak_Hash: Store Keccak_HashInstance in the main context.
Previously, the Keccak_HashInstance was separately allocated.
This could cause memory leaks on errors. For instance,
in php_hash_do_hash_hmac, the following code cleans up after
a file read error:

    if (n < 0) {
    	efree(context);
    	efree(K);
    	zend_string_release(digest);
    	RETURN_FALSE;
    }

This does not call the context's hash_final operation, which
was the only way to free the separately-allocated Keccak state.

The simplest fix is simply to place the Keccak_HashInstance state
inside the context object. Then it doesn't need to be freed.

As a result, there is no need to call hash_final in the
HashContext destructor: HashContexts cannot contain internally
allocated resources.
2020-06-30 14:26:48 +02:00
Christoph M. Becker
815a2be2ed Improve "VirtualProtect() failed" error messages
When `mprotect()` fails, the error message contains `errno` and the
respective `strerror()`; we add basically the same info on Windows.
2020-06-30 13:23:41 +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
Nikita Popov
c2b23d8cbe Fix leak in isDefaultValueAvailable()
Exposed in Symfony due to exit changes.
2020-06-30 11:16:56 +02:00
Christoph M. Becker
8c11d8fedb Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #70362: Can't copy() large 'data://' with open_basedir
2020-06-30 10:48:58 +02:00
Christoph M. Becker
993b19ae69 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #70362: Can't copy() large 'data://' with open_basedir
2020-06-30 10:48:07 +02:00
Christoph M. Becker
7f3bc64287 Fix #70362: Can't copy() large 'data://' with open_basedir
open_basedir is only relevant for plain files, so there is no need to
check it for other URL wrappers.
2020-06-30 10:46:53 +02:00
Xinchen Hui
c3af355755 Move to alpha2 section 2020-06-30 14:21:33 +08: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
Dmitry Stogov
1ca2fd2b16 Don't record "fake" closures 2020-06-29 20:37:50 +03:00
Christoph M. Becker
07ff243f07 Fix macro redifinition warnings in debug builds
MSVC considers these warnings[1] to be severe (level 1), so we better
fix the respective code.

[1] <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4005?view=vs-2019>
2020-06-29 19:11:22 +02:00
Christoph M. Becker
bf6720d582 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #63208: BSTR to PHP string conversion not binary safe
2020-06-29 19:06:56 +02:00
Christoph M. Becker
4af69b8477 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #63208: BSTR to PHP string conversion not binary safe
2020-06-29 19:06:00 +02:00
Christoph M. Becker
a385cfa7ad Fix #63208: BSTR to PHP string conversion not binary safe
A `BSTR` is similar to a `zend_string`; it stores the length of the
string just before the actual string, and thus the string may contain
NUL bytes.  However, `php_com_olestring_to_string()` is supposed to
deal with arbitrary `OLECHAR*`s which may not be `BSTR`s, so we
introduce `php_com_bstr_to_string()` and use it for the only case where
we actually have to deal with `BSTR`s which may contain NUL bytes.

Contrary to `php_com_olestring_to_string()` we return a `zend_string`,
so we can save the re-allocation when converting to a `zval`.

We also cater to `php_com_string_to_olestring()` not being binary safe,
with basically the same fix we did for `php_com_olestring_to_string()`.
2020-06-29 19:05:02 +02:00
Christoph M. Becker
43b5d58341 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #79756: finfo_file crash (FILEINFO_MIME)
2020-06-29 17:47:21 +02:00
Christoph M. Becker
dfac28f8d8 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79756: finfo_file crash (FILEINFO_MIME)
2020-06-29 17:46:46 +02:00
Christoph M. Becker
816b4c1235 Fix #79756: finfo_file crash (FILEINFO_MIME)
If `ctime` or `asctime` return `NULL`, we must not attempt to copy the
buffer, but rather return `NULL` as well.
2020-06-29 17:45:28 +02:00
Christoph M. Becker
aca621cf92 Fix #79749: Converting FFI instances to bool fails
Casting objects to bool is supposed to yield `true`.  Since the
`cast_object` handler is required now, we have to implement the
`_IS_BOOL` conversion there.
2020-06-29 16:02:58 +02:00
Nikita Popov
6e1990dea6 Don't accept objects instead of arrays in curl
This properly addresses the issue from bug #79741. Silently
interpreting objects as mangled property tables is almost
always a bad idea.

Closes GH-5773.
2020-06-29 15:56:22 +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
Xinchen Hui
d005a8e92b Fixed bug #79743 (Fatal error when assigning to array property with JIT enabled)
simple typo
2020-06-29 17:47:21 +08: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
Dmitry Stogov
46e38a1927 Fixed bug #79737 (Building embed as static fails during install step). 2020-06-29 11:14:20 +03:00
Nikita Popov
315ea609da Remove restriction on method call inlining
In PHP 8, we are guaranteed that $this exists, so we no longer have
to forbid this case.
2020-06-29 09:54:31 +02:00
Nikita Popov
bc62acf874 Merge branch 'PHP-7.4'
* PHP-7.4:
  Don't inline static call to instance method
2020-06-29 09:53:09 +02:00
Nikita Popov
fabcd9f14e Don't inline static call to instance method
Fixes the failure in bug79740.phpt with opcache.
2020-06-29 09:52:37 +02:00
George Peter Banyard
562ceae7bc Drop non-well formed numeric strings from math function tests 2020-06-28 19:32:11 +02:00
George Peter Banyard
892b32d839 Drop non-well numeric string in Intl test 2020-06-28 19:30:07 +02:00
George Peter Banyard
a9625f8b35 Drop non-well formed numeric strings in array function tests 2020-06-28 19:29:37 +02:00
George Peter Banyard
76643cd4f3 Drop non-well formed numeric strings in strings function tests 2020-06-28 19:29:14 +02:00
Nikita Popov
956dde0bc0 Simplify and fix php-cgi detection
Make it work for installed PHP binaries.
2020-06-26 14:17:56 +02:00
Nikita Popov
f930978b70 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79741
2020-06-26 12:29:43 +02:00
Nikita Popov
978cdb736a Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79741
2020-06-26 12:29:23 +02:00
Nikita Popov
43cd3f6814 Fixed bug #79741 2020-06-26 12:28:39 +02:00
David Carlier
1cbb62e82d Haiku proc_open build fix, *pty api resides on the BSD library
Closes GH-5770.
2020-06-26 12:06:21 +02:00
Nikita Popov
f89d84d622 Better leak fix for cgi -s / -w
We also need to go through request shutdown. The naming is a bit
confusing, but it's fine to go through fastcgi_request_done even
if not using fastcgi. Whether we loop or not is checked separately.
2020-06-26 11:07:55 +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
b6deace022 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79740
2020-06-26 10:33:12 +02:00
Nikita Popov
c5caa05171 Fixed bug #79740 2020-06-26 10:31:55 +02:00
Dmitry Stogov
9617c2a2f6 Use cheaper zend_hash_find_ex() to handle IS_CONST index 2020-06-26 11:18:04 +03:00
Nikita Popov
bcd7352b0c Fix uninitialized reads in min/max
We need to use the unstable comparison function here, the fallback
order is not initialized in this context.
2020-06-26 09:36:17 +02:00
Nikita Popov
afafe5443c Clear last error before shutting down memory manager
The last error is allocated using ZMM, make sure it's cleared
beforehand.

It would probably be better to allocate it persistently outside
of requests.
2020-06-26 09:30:08 +02:00
Ayesh Karunaratne
d114812faf [ci skip] Various typo fixes in stub comments and CHANGES file 2020-06-25 23:32:40 +02:00