Commit Graph

5377 Commits

Author SHA1 Message Date
Stanislav Malyshev
effa287b35 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Alternative fix for bug 77423
2021-01-26 22:55:16 -08:00
Stanislav Malyshev
fbf8c758fe Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Alternative fix for bug 77423
2021-01-26 22:55:10 -08:00
Christoph M. Becker
4a89e726bd Alternative fix for bug 77423
That bug report originally was about `parse_url()` misbehaving, but the
security aspect was actually only regarding `FILTER_VALIDATE_URL`.
Since the changes to `parse_url_ex()` apparently affect userland code
which is relying on the sloppy URL parsing[1], this alternative
restores the old parsing behavior, but ensures that the userinfo is
checked for correctness for `FILTER_VALIDATE_URL`.

[1] <5174de7cd3 (commitcomment-45967652)>
2021-01-26 22:54:58 -08:00
Nikita Popov
1bdd8f7ae4 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #42560
2021-01-19 11:44:22 +01:00
sj-i
5d31ee302d Fixed bug #42560
Check open_basedir after the fallback to the system's temporary
directory in tempnam().

In order to preserve the current behavior of upload_tmp_dir
(do not check explicitly specified dir, but check fallback),
new flags are added to check open_basedir for explicit dir
and for fallback.

Closes GH-6526.
2021-01-19 11:41:58 +01:00
Stanislav Malyshev
bf2bb39eac Fix test name 2021-01-04 01:52:59 -08:00
Stanislav Malyshev
8768621149 Fix bug #79405 - gethostbyname() silently truncates after a null byte 2021-01-04 01:19:21 -08:00
Christoph M. Becker
b132da7f9d Fix #77423: parse_url() will deliver a wrong host to user
To avoid that `parse_url()` returns an erroneous host, which would be
valid for `FILTER_VALIDATE_URL`, we make sure that only userinfo which
is valid according to RFC 3986 is treated as such.

For consistency with the existing url parsing code, we use ctype
functions, although that is not necessarily correct.
2021-01-04 01:19:18 -08:00
Stanislav Malyshev
434c2b1bdb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #77423: parse_url() will deliver a wrong host to user
2021-01-01 21:29:08 -08:00
Stanislav Malyshev
128fca4037 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix #77423: parse_url() will deliver a wrong host to user
2021-01-01 21:06:07 -08:00
Christoph M. Becker
2d3d72412a Fix #77423: parse_url() will deliver a wrong host to user
To avoid that `parse_url()` returns an erroneous host, which would be
valid for `FILTER_VALIDATE_URL`, we make sure that only userinfo which
is valid according to RFC 3986 is treated as such.

For consistency with the existing url parsing code, we use ctype
functions, although that is not necessarily correct.
2021-01-01 20:08:01 -08:00
Christoph M. Becker
57430e6f1e Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Replace sort() function calls with ksort() in basic ksort test
2020-12-27 18:32:03 +01:00
haszi
0db6f5267c Replace sort() function calls with ksort() in basic ksort test
Closes GH-6541.
2020-12-27 18:30:58 +01:00
Christoph M. Becker
7d9ddd61ec Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80384: limit read buffer size
2020-12-23 13:52:45 +01:00
Adam Seitz
70dfbe0068 Fix #80384: limit read buffer size
In the case of a stream with no filters, php_stream_fill_read_buffer
only reads stream->chunk_size into the read buffer. If the stream has
filters attached, it could unnecessarily buffer a large amount of data.

With this change, php_stream_fill_read_buffer only proceeds until either
the requested size or stream->chunk_size is available in the read buffer.

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>

Closes GH-6444.
2020-12-23 13:49:56 +01:00
Nikita Popov
c56701690a Detect overlarge step for character range()
This was done for int and float ranges, but not char ranges.

Fixes oss-fuzz #28666.
2020-12-16 17:01:15 +01:00
ekinhbayar
b0e858da8b Remove bug41347.phpt as the error cases are already tested
Closes GH-6506.
2020-12-11 16:47:40 +01:00
Christoph M. Becker
d6ae0f010e Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #77069: stream filter loses final block of data
2020-12-08 11:49:28 +01:00
Christoph M. Becker
65f5573bc8 Fix #77069: stream filter loses final block of data
Reading from a stream may return greater than zero, but nonetheless the
stream's EOF flag may have been set.  We have to cater to this
condition by setting the close flag for filters.

We also have to cater to that change in the zlib.inflate filter:

If `inflate()` is called with flush mode `Z_FINISH`, but the output
buffer is not large enough to inflate all available data, it fails with
`Z_BUF_ERROR`.  However, `Z_BUF_ERROR` is not fatal; in fact, the zlib
manual states: "If deflate returns with Z_OK or Z_BUF_ERROR, this
function must be called again with Z_FINISH and more output space
(updated avail_out) but no more input data, until it returns with
Z_STREAM_END or an error."  Hence, we do so.

Closes GH-6001.
2020-12-08 11:47:49 +01:00
Nikita Popov
2d467abc46 Fix another typed resource issue in unserialization
We also need to discard old entries in the ref_props HT when values
are overwritten.

We should really forbid these kinds of overwrites. I believe they
can only occur in manually crafted serialization strings, and
cause so many problems...

Fixes oss-fuzz #28257.
2020-12-07 12:36:09 +01:00
Nikita Popov
77325c4448 Fix removal of type source during unserialization
Missed a check for info in this code. Add it, and add an assertion
in type source removal to make it easier to catch this issue.

Fixes oss-fuzz #28208 and #28257.
2020-12-04 12:56:05 +01:00
Christian Schneider
7bc7a80445 Make is_file() and friends return false when path contains 0-byte
These functions now return false silently:
is_writable, is_readable, is_executable, is_file, is_dir, is_link,
file_exists

These functions now throw a warning an return false (rather than
throwing a ValueError):
fileperms, fileinode, filesize, fileowner, filegroup, filetype,
fileatime, filemtime, filectime, lstat, stat

See also https://externals.io/message/112333.

Closes GH-6478.
2020-12-03 09:43:15 +01:00
Nikita Popov
ed9532cff0 Fix another ref source management bug in unserialize
When we overwrite an existing property during unserialization,
we also have to drop the ref source from it.
2020-11-30 14:23:54 +01:00
Nikita Popov
217f247bb5 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #80411
2020-11-25 17:24:49 +01:00
Nikita Popov
2fb12be84c Fixed bug #80411
References to null-serializations are stored as null, and as such
are part of the reference count.

Reminds me that we really need to deprecate the mess that is
Serializable.
2020-11-25 17:23:42 +01:00
Nikita Popov
f5b93626a6 Fix unserialization ref source management, again
Handle one case the previous patch did not account for: If
unserialization of data fails, we should still register a ref
source.

Also add an extra test for a reference between two typed properties,
as this used to be handled incorrectly earlier.
2020-11-25 17:04:07 +01:00
Nikita Popov
7a3f25e370 Fix ref source management during unserialization
Only register the slot for adding ref sources later if we didn't
immediately register one. Also avoids leaking a ref source if
it is added early and the assignment fails.

Fixes oss-fuzz #27628.
2020-11-25 12:25:07 +01:00
Christoph M. Becker
c7343510e4 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #72964: White space not unfolded for CC/Bcc headers
2020-11-19 19:26:56 +01:00
Christoph M. Becker
881e43a03c Fix #72964: White space not unfolded for CC/Bcc headers
`\r\n` does only terminate a header, if not followed by `\t` or ` `.
We have to cater to that when determining the end position of the
respective headers.

Closes GH-6420.
2020-11-19 19:25:03 +01:00
Christoph M. Becker
a08a2b48b4 Strip trailing line breaks and periods from Windows error messages
PHP error messages should not contain line breaks, so we remove these
from the Windows specific error messages.  We also remove trailing
periods for the same reason.

Closes GH-6423.
2020-11-12 16:42:28 +01:00
Nikita Popov
2875d0f920 Fix memory leak when user filter onCreate returns false 2020-11-12 12:18:33 +01:00
Christoph M. Becker
b8f2531ff0 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80266: parse_url silently drops port number 0
2020-11-04 14:57:17 +01:00
Christoph M. Becker
00e41a10b8 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #80266: parse_url silently drops port number 0
2020-11-04 14:54:32 +01:00
Christoph M. Becker
2cab085bb3 Fix #80266: parse_url silently drops port number 0
As of commit 81b2f3e[1], `parse_url()` accepts URLs with a zero port,
but does not report that port, what is wrong in hindsight.

Since the port number is stored as `unsigned short` there is no way to
distinguish between port zero and no port.  For BC reasons, we thus
introduce `parse_url_ex2()` which accepts an output parameter that
allows that distinction, and use the new function to fix the behavior.

The introduction of `parse_url_ex2()` has been suggested by Nikita.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=81b2f3e5d9fcdffd87a4fcd12bd8c708a97091e1>

Closes GH-6399.
2020-11-04 14:53:19 +01:00
Nikita Popov
3bd3651bcc Fixed bug #80290
Dropping the dtor arg args[3] rather than using STR_COPY: Since
PHP 8, we no longer support separation in call_user_function(),
so we also don't need to worry about things like arguments being
replaced with references.
2020-10-30 11:13:35 +01:00
Nikita Popov
d776d25a8e Don't throw for out of bounds offsets in strspn()
Make strspn($str1, $str2, $offset, $length) behaviorally
equivalent to strspn(substr($str1, $offset, $length), $str2)
by not throwing for out of bounds offset.

There have been two reports that this change cause issues,
including bug #80285.
2020-10-27 11:42:01 +01:00
Nikita Popov
682357c5b4 Skip bug46024.phpt under asan
There is a legitimate leak here, but I don't think it's worthwhile
to fix it. It involves a process terminated while printing phpinfo.
2020-10-27 10:35:12 +01:00
Nikita Popov
1c157d3fa2 Fixed bug #80256
Remove the transfer_encoding stream filter immediately when we
destroy the old stream, to make sure it doesn't get attached to
the new stream.
2020-10-20 15:35:41 +02:00
Nikita Popov
6a8c094e2d Remove string length limit from levenshtein()
As noted on https://bugs.php.net/bug.php?id=80073, I don't think
having this limitation makes sense. The similar_text() function
has much worse asymptotic complexity than levenshtein() and does
not enforce such a limitation. levenshtein() does have fairly high
memory requirements, but they are a fixed factor of the string
length (and subject to memory limit).
2020-10-09 16:12:08 +02:00
Nikita Popov
79484b4f8a Update ext/sockets parameter names
Also change $max_length to $length in a number of filesystem APIs,
where our usage was inconsistent.

Closes GH-6276.
2020-10-06 12:12:43 +02:00
Nikita Popov
d9dce839f7 Update ext/posix parameter names
Closes GH-6275.
2020-10-06 09:49:40 +02:00
Christoph M. Becker
54435c9b43 Fix #64060: lstat_stat_variation7.phpt fails on certain file systems
Closes GH-6194.
2020-10-02 18:54:10 +02:00
Máté Kocsis
6b00196e04
Review parameter names in ext/pcre
Closes GH-6259
2020-10-02 11:55:23 +02:00
Nikita Popov
25f1c405ff Update ext/standard parameter names
Closes GH-6214.
2020-09-29 16:49:46 +02:00
Nikita Popov
59aa21c735 Don't accept dir handle in Directory methods
This is an artifact of the shared implementation with readdir() etc.
The method versions should not accept an explicit dir handle, as
they work on the dir handle from the object.
2020-09-29 14:50:40 +02:00
Nikita Popov
de2d38d531 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #80137
  Fix bug #80138
2020-09-29 10:59:46 +02:00
Nikita Popov
1fafcd2b28 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix bug #80137
  Fix bug #80138
2020-09-29 10:59:32 +02:00
Matthias Karbe
f5afd0a827 Fix bug #80137
Skip getprotobyname() and getprotobynumber() tests on *nix if there
is no /etc/protocols file.

Closes GH-6193.
2020-09-29 10:58:00 +02:00
Matthias Karbe
2899137391 Fix bug #80138
Skip getservbyname() and getservbyport() tests on *nix if there is
no /etc/services file.

Closes GH-6191.
2020-09-29 10:57:20 +02:00
Nikita Popov
cafceea742 Update mbstring parameter names
Closes GH-6207.
2020-09-28 09:51:58 +02:00