Commit Graph

1154 Commits

Author SHA1 Message Date
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
Christoph M. Becker
89d4b6b790 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #80384: limit read buffer size
2020-12-23 13:53:19 +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
7904a087ec Back memory stream by a zend_string
This allows reusing an existing zend_string inside a memory stream
without reallocating. For non-readonly streams, the string will
only get separated on write.
2020-12-18 17:07:07 +01:00
Nikita Popov
9ec6392d80 Remove unused smax member from memory stream 2020-12-18 16:40:23 +01:00
Christoph M. Becker
615197ae3d Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #77069: stream filter loses final block of data
2020-12-08 11:49:41 +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
39c59e084c Merge branch 'PHP-8.0'
* PHP-8.0:
  Suppress stream errors in mysqlnd
2020-11-30 15:06:40 +01:00
Nikita Popov
24a19cc232 Suppress stream errors in mysqlnd
mysqlnd currently sets error_reporting=0 to suppress errors while
writing to streams. Unfortunately these errors are still visible
to userland error handlers, which is a source of confusion.
See for example https://bugs.php.net/bug.php?id=80412.

Instead add a stream flag that suppresses the emission of
read/write errors in the first place, and set it in mysqlnd.

I think it might be useful to have this option for userland as
well in the future, but for now this is just an internal
mechanism.

Closes GH-6458.
2020-11-30 15:06:28 +01:00
George Peter Banyard
150ebfdf77 Suppress bogus [-Wlogical-op] warning from GCC
See GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602
which emits the warning for (errno == EWOULDBLOCK || errno == EAGAIN)
which is the correct way of handling errors as the value of EWOULDBLOCK
and EAGAIN is implementation defined.

Therefore introduce a new macro function PHP_IS_TRANSIENT_ERROR()
which handles the case when EWOULDBLOCK and EAGAIN are identical.

Thanks to @twose for the idea.
2020-10-10 14:45:20 +01:00
Christoph M. Becker
ffa57164a8 Clear error flag instead of toggling it
The toggling of the `REPORT_ERRORS` looks fishy, and likely was
intented as clearing.

Closes GH-6190.
2020-09-23 23:26:58 +02:00
Christoph M. Becker
05edf64436 Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #76735: Incorrect message in fopen on invalid mode
2020-09-23 11:14:06 +02:00
Christoph M. Becker
a89ac98f15 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #76735: Incorrect message in fopen on invalid mode
2020-09-23 10:54:59 +02:00
Christoph M. Becker
2576c57a51 Fix #76735: Incorrect message in fopen on invalid mode
We have to log errors in `stream_opener` callbacks to the wrapper's
error log, because otherwise we may pick up an unrelated `errno` or a
most generic message.

Closes GH-6187.
2020-09-23 10:54:06 +02:00
Christoph M. Becker
544dbe8ef9 Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #76943: Inconsistent stream_wrapper_restore() errors
2020-09-22 16:14:03 +02:00
Christoph M. Becker
ff0f6c26c2 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #76943: Inconsistent stream_wrapper_restore() errors
2020-09-22 16:12:37 +02:00
Christoph M. Becker
5ed0602ec6 Fix #76943: Inconsistent stream_wrapper_restore() errors
If restoring of any not registered built-in wrapper is requested, the
function is supposed to fail with a warning, so we have to check this
condition first.

Furthermore, to be able to detect whether a built-in wrapper has been
changed, it is not sufficient to check whether *any* userland wrapper
has been registered, but rather whether the specific wrapper has been
modified.

Closes GH-6183.
2020-09-22 16:11:35 +02:00
Christoph M. Becker
d893404fb9 Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #79423: copy command is limited to size of file it can copy
2020-09-22 13:19:06 +02:00
Christoph M. Becker
f445e9cb93 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79423: copy command is limited to size of file it can copy
2020-09-22 13:16:59 +02:00
Christoph M. Becker
4000780b3d Fix #79423: copy command is limited to size of file it can copy
Passing `NULL` as `lpFileSizeHigh` to `GetFileSize()` gives wrong
results for files larger than 0xFFFFFFFF bytes.  We fix this by using
`GetFileSizeEx()`, and let the mapping fail, if the file size is too
large for the architecture.

Closes GH-5319.
2020-09-22 13:15:07 +02:00
Christoph M. Becker
6fa2493789 Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix mmap copying
2020-09-21 16:09:17 +02:00
Christoph M. Becker
19c844594e Fix mmap copying
Instead of attempting to map large files into memory at once, we map
chunks of at most `PHP_STREAM_MMAP_MAX` bytes, and repeat that until we
hit the point where `php_stream_seek()` fails (see bug 54902), and copy
the rest of the file by reading and writing small chunks.

We also fix the mapping behavior for zero bytes on Windows, which did
not error (as with `mmap()`), but would have mapped the remaining file.
2020-09-21 16:07:57 +02:00
Christoph M. Becker
4d86000541 Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #80067: Omitting the port in bindto setting errors
2020-09-11 14:49:07 +02:00
Christoph M. Becker
e41867888a Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #80067: Omitting the port in bindto setting errors
2020-09-11 14:46:51 +02:00
Christoph M. Becker
dfb3a79914 Fix #80067: Omitting the port in bindto setting errors
A recent commit[1] which fixed a memory leak introduced a regression
regarding the formerly liberal handling of IP addresses to bind to.  We
fix this by reverting that commit, and fix the memory leak where it
actually occurs.  In other words, this fix is less intrusive than the
former fix.

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

Closes GH-6104.
2020-09-11 14:44:12 +02:00
Christoph M. Becker
c7cba01b88 Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #80048: Bug #69100 has not been fixed for Windows
2020-09-03 15:46:30 +02:00
Christoph M. Becker
2f4a2a9316 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #80048: Bug #69100 has not been fixed for Windows
2020-09-03 15:45:33 +02:00
Christoph M. Becker
1848ccdae2 Fix #80048: Bug #69100 has not been fixed for Windows
We fix the erroneous length calculation on Windows, too.

Closes GH-6067.
2020-09-03 15:43:19 +02:00
Nikita Popov
4cc4f9c00a Use standard types in fopencookie test
Instead of internal __size_t / __off64_t types use ssize_t and off64_t.
This makes it work on musl as well.
2020-08-05 10:39:37 +02:00
Nikita Popov
b0d139456a Use standard types in fopencookie test
Instead of internal __size_t / __off64_t types use ssize_t and off64_t.
This makes it work on musl as well.
2020-08-05 09:45:51 +02:00
George Peter Banyard
c3105a1f8d ValueError for empty path in stream code
Closes GH-5902
2020-07-31 13:39:58 +01:00
twosee
ab9d10d023 Merge branch 'PHP-7.4'
* PHP-7.4:
  Handle bindto error
2020-07-29 17:48:01 +08:00
twosee
12bd3cc146 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Handle bindto error
2020-07-29 17:46:57 +08:00
twosee
0b8c83f593 Handle bindto error
Closes GH-5903.
2020-07-29 17:46:27 +08:00
George Peter Banyard
73e070a614 Refactor user streams to use ZPP class check
Closes GH-5876
2020-07-28 17:12:40 +01:00
Nikita Popov
a1ab7bbc3a Simplify user_stream_create_object 2020-07-23 16:20:25 +02:00
Martin Schröder
547d98b81d Support socketpairs in proc_open()
Closes GH-5777.
2020-07-14 10:35:45 +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
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +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
Alex Dowad
e673c63989 Correct comment in plain_wrapper.c (refers to microseconds, not milliseconds) 2020-06-24 22:26:00 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00
twosee
7d6a0ba808 Fix expression warnings and break warnings
Close GH-5675.
2020-06-07 10:41:11 +02:00
George Peter Banyard
8e66d22f7e Fix [-Wundef] warning in streams implementation 2020-05-12 22:01:20 +02:00
Christoph M. Becker
69888c3ff1 Fix #79467: data:// wrappers are writable
Despite the docs claiming that data: wrappers would not be writable[1],
they are implemented as writing to a memory stream.  That does not seem
to be particularly sensible, so we disallow writing altogether.

[1] <https://www.php.net/manual/en/wrappers.data.php#refsect1-wrappers.data-options>
2020-05-03 12:19:37 +02:00
Nikita Popov
56d30bb35a Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79468
2020-04-14 12:02:22 +02:00
Nikita Popov
ef56b2c977 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79468
2020-04-14 12:01:51 +02:00
dinosaur
95eaccd0bb Fixed bug #79468
Close the stream filter resources when removing them from the stream.
2020-04-14 11:59:51 +02:00
Christoph M. Becker
f078bca729 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #78210: Invalid pointer address
2020-03-11 11:32:46 +01:00
Christoph M. Becker
8657f03084 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #78210: Invalid pointer address
2020-03-11 11:31:26 +01:00
Christoph M. Becker
53797c206a Fix #78210: Invalid pointer address
This is actually about three distinct issues:

* If an empty string is passed as $address to `stream_socket_sendto()`,
  the `sa` is not initialized, so we must not pass it as `addr` to
  `php_stream_xport_sendto()`.

* On POSIX, `recvfrom()` truncates messages which are too long to fit
  into the specified buffer (unless `MSG_PEEK` is given), discards the
  excessive bytes, and returns the buffer length.  On Windows, the same
  happens, but `recvfrom()` returns `SOCKET_ERROR` with the error code
  `WSAEMSGSIZE`.  We have to catch this for best POSIX compatibility.

* In `php_network_parse_network_address_with_port()`, we have to zero
  `in6` (not only its alias `sa`) to properly support IPv6.

Co-Authored-By: Nikita Popov <nikita.ppv@googlemail.com>
2020-03-11 11:30:15 +01:00
Nikita Popov
941a3b6ccd Remove unnecessary uses of CHECK_SILENT
If no error is passed, it is always silent.
2020-03-06 16:36:45 +01:00
George Peter Banyard
b3f17ea5d5 Promote invalid mode/unknow option from Warning to ValueError for plain streams.
Closes GH-5076
2020-02-04 22:25:43 +01:00
Nikita Popov
a2e4392439 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78902
  Add unit test for bug #78902
2020-01-23 14:58:15 +01:00
Nikita Popov
6489e29831 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #78902
  Add unit test for bug #78902
2020-01-23 14:58:10 +01:00
liudaixiao
67421a780d Fixed bug #78902 2020-01-23 14:57:16 +01:00
Máté Kocsis
d1764ca330
Make error messages more consistent by fixing capitalization
Closes GH-5066 As a first step, let's capitalize their initial letter when it is applicable.
2020-01-17 14:52:46 +01:00
Máté Kocsis
0b4778c377
Fix #78880: Another bunch of spelling errors 2020-01-16 09:46:47 +01:00
Nikita Popov
d5c886ab7d Merge branch 'PHP-7.4'
* PHP-7.4:
  Properly propagate url_stat exceptions during include
2019-12-30 22:57:07 +01:00
Nikita Popov
f77747b06c Properly propagate url_stat exceptions during include
Make sure we abort operations early, and that we don't emit
additional warnings or errors if an exception has been thrown.
2019-12-30 22:56:42 +01:00
Máté Kocsis
e1b57310b1
Use RETURN_THROWS() during ZPP in main, sapi, win32, and Zend 2019-12-30 17:38:10 +01:00
Nikita Popov
5902b35f85 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79000
2019-12-20 11:38:01 +01:00
Nikita Popov
10eb0b3110 Fixed bug #79000
Don't report EAGAIN/EWOULDBLOCK as errors for fwrite on
non-blocking socket streams. This matches behavior for fread,
as well as behavior for plain file streams.

Closes GH-5026.
2019-12-20 11:37:43 +01:00
Christoph M. Becker
c1a6f2b9cc Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #78883: fgets(STDIN) fails on Windows
2019-12-02 16:53:35 +01:00
Christoph M. Becker
996f217aa5 Fix #78883: fgets(STDIN) fails on Windows
We add the `is_seekable` member to `php_stdio_stream_data`, and prefer
that over `is_pipe`, since the latter is simply a misnomer.  We keep
`is_pipe` for now for Windows only, though, because we need special
support for pipes there.  We also fix the misaligned bitfield which
formerly took 33 bit.
2019-12-02 16:52:32 +01:00
Nikita Popov
0b689c163e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #77930: Remove mmap limit
2019-10-31 09:37:27 +01:00
Nikita Popov
333d607d47 Fix bug #77930: Remove mmap limit
First, the limitation already doesn't trigger if you copy the whole
file (i.e. use copy() or stream_copy_to_stream() and don't specify
a length). This happens because length will be 0 at the time of the
check and only later calculated based on the file size. This means
that we're already completely blowing the length limit for what is
likely the most common case, and it doesn't seem like anyone complained
about that.

Second, the premise of the code comment ("to avoid runaway swapping")
seems incorrect to me. Because this performs a file-backed non-private
mmap, no swap backing is needed for the mapping. Concerns over "memory
usage" are also misplaced, as this is a virtual mapping.
2019-10-31 09:37:05 +01:00
Nikita Popov
5cbe5a538c Don't use chunking for stream writes
We're currently splitting up large writes into 8K size chunks, which
adversely affects I/O performance in some cases. Splitting up writes
doesn't make a lot of sense, as we already must have a backing buffer,
so there is no memory/performance tradeoff to be made here.

This change disables the write chunking at the stream layer, but
retains the current retry loop for partial writes. In particular
network writes will typically only write part of the data for large
writes, so we need to keep the retry loop to preserve backwards
compatibility.

If issues due to this change turn up, chunking should be reintroduced
at lower levels where it is needed to avoid issues for specific streams,
rather than unnecessarily enforcing it for all streams.
2019-10-30 13:03:45 +01:00
Remi Collet
28ed73d94a Merge branch 'PHP-7.4'
* PHP-7.4:
  NEWS
  Fix #78662: stream_write bad error detection
2019-10-11 13:38:29 +02:00
Remi Collet
5a024d2c5b Fix #78662: stream_write bad error detection 2019-10-11 13:36:58 +02:00
Nikita Popov
a748d27c9b Merge branch 'PHP-7.4' 2019-10-10 12:08:17 +02:00
Nikita Popov
f43f493e09 Also check for exception after stream_eof 2019-10-10 12:08:04 +02:00
Nikita Popov
595e8c6773 Merge branch 'PHP-7.4' 2019-10-10 11:17:55 +02:00
Nikita Popov
6878c583b0 Report error if stream_read is not implemented
We need to return -1 in this case. Slightly restructure the code
to avoid unnecessary conditions.
2019-10-10 11:13:10 +02:00
Nikita Popov
41526976c5 Merge branch 'PHP-7.4' 2019-10-08 12:35:47 +02:00
Nikita Popov
196f9697ef Merge branch 'PHP-7.3' into PHP-7.4 2019-10-08 12:35:35 +02:00
Nikita Popov
2fdd142f99 Check for exception after applying stream filters
This makes the stream opening actually fail, and avoids assertion
failures when we tokenize with EG(exception) set.

Also avoid throwing an additional warning after an exception has
already been thrown.
2019-10-08 12:32:57 +02:00
Joe Watkins
733a1e9df0
Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #76859 stream_get_line skips data if used with data-generating filter
2019-10-03 06:52:25 +02:00
Joe Watkins
de83036f13
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #76859 stream_get_line skips data if used with data-generating filter
2019-10-03 06:51:56 +02:00
Joe Watkins
5b1bb23edf
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix #76859 stream_get_line skips data if used with data-generating filter
2019-10-03 06:51:10 +02:00
Konstantin Kopachev
05560b67bc
Fix #76859 stream_get_line skips data if used with data-generating filter
stream_get-line repeatedly calls php_stream_fill_read_buffer until
enough data is accumulated in buffer. However, when stream contains
filters attached to it, then each call to fill buffer essentially
resets buffer read/write pointers and new data is written over old.
This causes stream_get_line to skip parts of data from stream
This patch fixes such behavior, so fill buffer call will append.
2019-10-03 06:50:43 +02:00
Nikita Popov
32c20d5670 Remove unused mmap_file + mmap_len from basic_globals 2019-09-27 13:00:07 +02:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00
Nikita Popov
11f3e24190 Fixed bug #78506 2019-09-11 10:27:32 +02:00
Nikita Popov
9ec61e43d4 Fix pipe detection and stream position handling
There are two related changes here:
1. Also check for S_ISCHR/FILE_TYPE_CHAR when checking for pipes, so
   that we detect ttys as well, which are also not seekable.
2. Always set position=-1 (i.e. ftell will return false) when a pipe
   is detected. Previously position=0 was sometimes used, depending on
   whether we're on Windows/Linux and whether the FD or FILE codepath
   was used.
2019-09-05 18:29:15 +02:00
Nikita Popov
724a4662b8 Replace strncat in filter implementation
In this case we already know exactly where we need to write, no
need to use strncat at all.
2019-08-23 16:18:50 +02:00
Nikita Popov
a18ad194c4 Fixed bug #78396 2019-08-12 10:45:13 +02:00
Nikita Popov
536c91c535 Merge branch 'PHP-7.3' into PHP-7.4 2019-07-29 17:34:37 +02:00
Nikita Popov
44fe025c28 Merge branch 'PHP-7.2' into PHP-7.3 2019-07-29 17:34:16 +02:00
Albert Casademont
dc7aa22b18 Fix bug #78326
Similar to what fread() does, truncate the stream_get_contents()
result if the original buffer was way too large.
2019-07-29 17:33:57 +02:00
Nikita Popov
1cbcf0f4f1 Throw notice for plain wrapper fread/fwrite errors
Similar to what is done for socket read/write errors.
2019-07-25 10:42:10 +02:00
Nikita Popov
d59aac58b3 Report errors from stream read and write operations
The php_stream_read() and php_stream_write() functions now return
an ssize_t value, with negative results indicating failure. Functions
like fread() and fwrite() will return false in that case.

As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams
should not be regarded as error conditions, and be reported as
successful zero-length reads/writes instead. The handling of EINTR
remains unclear and is internally inconsistent (e.g. some code-paths
will automatically retry on EINTR, while some won't).

I'm landing this now to make sure the stream wrapper ops API changes
make it into 7.4 -- however, if the user-facing changes turn out to
be problematic we have the option of clamping negative returns to
zero in php_stream_read() and php_stream_write() to restore the
old behavior in a relatively non-intrusive manner.
2019-07-22 17:17:28 +02:00
Nikita Popov
56a2ea7aa2 Merge branch 'PHP-7.3' into PHP-7.4 2019-07-17 15:59:22 +02:00
Nikita Popov
79efd55fc3 Merge branch 'PHP-7.2' into PHP-7.3 2019-07-17 15:59:14 +02:00
Nikita Popov
b864abfe23 Fixed bug #69100 2019-07-17 15:58:29 +02:00
Nikita Popov
07a4d134ab Avoid duplicate fstat() for includes
By adding a flag to avoid forced fstat for includes. The two fstats
will happen back to back and we don't care about a possible
invalidation.

I was hoping to move this higher up in the stack and make the
ISREG check somewhere in fsizer of fixup, but this doesn't really
seem to be possible. E.g. an FP stdin handle will not be a regular
file but of course needs to be allowed. Additionally custom stream
wrappers may not implement this functionality.
2019-07-17 14:48:51 +02:00
Nikita Popov
6bebe833a2 Fix use-after-free in stream freeing during shutdown
Streams will be freed in an unpredictable order during shutdown.
Ignore explicit calls to php_stream_close() entirely to avoid
use-after-free -- instead let the stream resource destructor
deal with it. We have to account for a few special cases:

 * Enclosed streams should be freed, as the resource destructor
   will forward to the enclosing stream.
 * Stream cookies also directly free streams, because we delegate
   to the cookie destruction if one exists.
 * Mysqlnd also directly frees streams, because it explicitly
   removes stream resources (because mysqlnd!)
2019-06-27 09:45:23 +02:00
Nikita Popov
7cbd4f31c4 Remove copy argument from php_glob_stream_get_path/pattern
This is unused, and shouldn't be part of the API.
2019-06-19 17:27:09 +02:00
Nikita Popov
f26e77b05f Avoid memcpy UB in streams 2019-06-19 15:09:00 +02:00
Nikita Popov
a31f46421d Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions

And convert some object to string conversion related recoverable
fatal errors into Error exceptions.

Improve exception safety of internal code performing string
conversions.
2019-06-05 14:25:07 +02:00
Jakub Zelenka
3c056a9e75 Enable TLS 1.3 by default 2019-04-28 17:37:43 +01:00
codarrenvelvindron
5c05f5e6d3 Added tls 1.3 support for PHP 2019-04-28 17:37:43 +01:00
Nikita Popov
2b28f71891 Use readdir() instead of readdir_r()
readdir_r() is deprecated in modern glibc versions. readdir() is
thread safe in practice, as long as there are no concurrent accesses
on the *same* directory stream.
2019-04-11 16:52:36 +02:00
Stanislav Malyshev
ebf3711fca Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix bug #77630 - safer rename() procedure
2019-03-04 09:18:55 -08:00
Stanislav Malyshev
609195e991 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix bug #77630 - safer rename() procedure
2019-03-04 09:18:22 -08:00
Stanislav Malyshev
2cc1ab81c2 Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Fix bug #77630 - safer rename() procedure
2019-03-04 09:17:14 -08:00
Stanislav Malyshev
e3133e4db7 Fix bug #77630 - safer rename() procedure
In order to rename safer, we do the following:
- set umask to 077 (unfortunately, not TS, so excluding ZTS)
- chown() first, to set proper group before allowing group access
- chmod() after, even if chown() fails
2019-03-04 09:15:11 -08:00
Nikita Popov
a8daef51e1 Merge branch 'PHP-7.3' into PHP-7.4 2019-02-25 13:02:58 +01:00
Xinchen Hui
3c3d59aa39 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fixed bug #77664 (Segmentation fault when using undefined constant in custom wrapper)
2019-02-25 14:42:01 +08:00
Xinchen Hui
4a72dd782d Fixed bug #77664 (Segmentation fault when using undefined constant in custom wrapper) 2019-02-25 14:41:46 +08:00
Nikita Popov
2ca123e8f0 Merge branch 'PHP-7.3' into PHP-7.4 2019-02-11 15:50:53 +01:00
Nikita Popov
4da67537c1 Merge branch 'PHP-7.2' into PHP-7.3 2019-02-11 15:50:47 +01:00
Ahmed Abdou
ec28d4c247 Fix bug #51068 (glob:// do not support current path relative)
Fix DirectoryIterator glob://* current path relative queries
2019-02-11 15:50:27 +01:00
Nikita Popov
52c2d47c90 Merge branch 'PHP-7.3' into PHP-7.4 2019-02-11 11:33:18 +01:00
Nikita Popov
be64a06b1c Merge branch 'PHP-7.2' into PHP-7.3 2019-02-11 11:33:04 +01:00
johnstevenson
fe4d7248cc Fix #77552: Uninitialized buffer in stat functions 2019-02-11 11:31:55 +01:00
Peter Kokot
92ac598aab Remove local variables
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.

A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.

This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.

With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.

Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files.  All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
2019-02-03 21:03:00 +01:00
Zeev Suraski
0cf7de1c70 Remove yearly range from copyright notice 2019-01-30 11:03:12 +02:00
Dmitry Stogov
cec091176c Replace zend_hash_apply... with ZEND_HASH_FOREACH... 2018-12-19 02:49:56 +03:00
Gabriel Caruso
cdd8368d6f Clean up unnecessary ternary expressions and simplify some returns
- Simplify conditions
- Use ZEND_HASH_APPLY_* instead of hard-coded booleans
- Use ZEND_NORMALIZE_BOOL
- Drop sign in favor of ZEND_NORMALIZE_BOOL
2018-12-03 01:22:14 +01:00
Anatol Belski
3c4cf40064 Merge branch 'PHP-7.3'
* PHP-7.3:
  Simplify assignment on 64-bit
2018-11-17 22:57:16 +01:00
Anatol Belski
b0591f5e46 Simplify assignment on 64-bit 2018-11-17 22:56:39 +01:00
Anatol Belski
9c9178af51 Merge branch 'PHP-7.3'
* PHP-7.3:
  Fix error condition
  Fixed bug #77081 ftruncate() changes seek pointer in c mode
2018-10-30 20:50:07 +01:00
Anatol Belski
ee9d879f57 Fix error condition 2018-10-30 20:43:45 +01:00
Anatol Belski
8827cc34cf Fixed bug #77081 ftruncate() changes seek pointer in c mode 2018-10-30 20:42:00 +01:00
Dmitry Stogov
d1e14e2cc0 Merge branch 'PHP-7.3'
* PHP-7.3:
  Make php_plain_files_wrapper to be writable (workaround for swoole)
2018-10-24 11:50:18 +03:00
Dmitry Stogov
770fe51bfd Make php_plain_files_wrapper to be writable (workaround for swoole) 2018-10-24 11:49:44 +03:00
Peter Kokot
1ad08256f3 Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:56:38 +02:00
Peter Kokot
1c850bfcca Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:55:24 +02:00
Peter Kokot
60a69daec6 Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:54:08 +02:00
Peter Kokot
03f3b8479b Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:51:01 +02:00
Anatol Belski
8b4b41696e Merge branch 'PHP-7.3'
* PHP-7.3:
  Fixed bug #76803 ftruncate changes file pointer
2018-08-28 15:43:34 +02:00
Anatol Belski
7728160784 Fixed bug #76803 ftruncate changes file pointer 2018-08-28 15:42:39 +02:00
Peter Kokot
3ceecaa9a0 Replace HAVE_ST_BLOCKS with HAVE_STRUCT_STAT_ST_BLOCKS
Since Autoconf 2.50+ macro AC_STRUCT_ST_BLOCKS defines the new
HAVE_STRUCT_STAT_ST_BLOCKS symbol and has deprecated the previous
HAVE_ST_BLOCKS.

PHP 5.3 required Autoconf 2.13 (released in 1999) or newer, since PHP
5.4 the autoconf 2.59 (released in 2003) or newer was required, and
since PHP 7.2, autoconf 2.64 (released in 2008) or newer is required.
2018-08-24 18:33:23 +02:00
Gabriel Caruso
84b195d9fc Fix some misspellings 2018-08-12 16:15:45 +02:00
Dmitry Stogov
c42f0ba4f7 Removed useless IS_UNDEF checks 2018-07-31 12:23:46 +03:00
Peter Kokot
d2184efb7b Replace obsolete AC_STRUCT_ST_BLKSIZE and AC_STRUCT_ST_RDEV
Autoconf 2.50 released in 2001 has made several macros obsolete. Instead
of the AC_STRUCT_ST_BLKSIZE and AC_STRUCT_ST_RDEV the new
AC_CHECK_MEMBERS should be used.

When checking for the presence of stat struct members st_blkzize and
st_rdev the new AC_CHECK_MEMBERS macro defines new constants
HAVE_STRUCT_STAT_ST_BLKSIZE and HAVE_STRUCT_STAT_ST_RDEV.

Old constants HAVE_ST_BLKSIZE and HAVE_ST_RDEV need to be replaced
respectively in PHP code (this patch) and in PHP extenstions if they use
them.

PHP 5.4 to 7.1 require Autoconf 2.59+ version, PHP 7.2 and above require
2.64+ version, and the PHP 7.2 phpize script requires 2.59+ version which
are all greater than above mentioned 2.50 version.
2018-07-29 13:59:40 +02:00
Peter Kokot
a5e80b22e1 Fix typos in code comments 2018-07-25 11:57:11 +02:00
Peter Kokot
8d3f8ca12a Remove unused Git attributes ident
The $Id$ keywords were used in Subversion where they can be substituted
with filename, last revision number change, last changed date, and last
user who changed it.

In Git this functionality is different and can be done with Git attribute
ident. These need to be defined manually for each file in the
.gitattributes file and are afterwards replaced with 40-character
hexadecimal blob object name which is based only on the particular file
contents.

This patch simplifies handling of $Id$ keywords by removing them since
they are not used anymore.
2018-07-25 00:53:25 +02:00
Dmitry Stogov
b6cc4d2009 Use zval_ptr_dtor() instead of zval_dtor() in internal functions that destroy new created object (This is safer and produces less code) 2018-07-05 11:54:26 +03:00
Dmitry Stogov
fcfa006a4e Avoid useless stream buffer copying and workaround with chunk_size manipulation. 2018-06-14 02:34:17 +03:00
Anatol Belski
9cd2d77514 Fixed bug #76422 ftruncate fails on files > 2GB 2018-06-09 11:28:24 +02:00
Dmitry Stogov
0b90cf85a6 Removed "dead" code (zend_hash_update() never fails) 2018-06-01 11:58:57 +03:00
Dmitry Stogov
d90c6f2443 Removed useless zval_ptr_dtor() 2018-05-29 17:58:06 +03:00
Dmitry Stogov
5eb1f92f31 Use zend_string_release_ex() instread of zend_string_release() in places, where we sure about string persistence. 2018-05-28 16:27:12 +03:00
Dmitry Stogov
eafa92ba9d zend_fcall_info_cache.calling_scope is not used by zend_call_function() and doesn't have to be initialized.
It's used only as a result of zend_is_callable() in forward_static_call and spl_autoload.
2018-05-03 19:27:04 +03:00
Gabriel Caruso
8034fdc9d9 Use int instead of integer in proto 2018-02-02 22:32:15 +01:00
Xinchen Hui
a6519d0514 year++ 2018-01-02 12:57:58 +08:00
Xinchen Hui
7a7ec01a49 year++ 2018-01-02 12:55:14 +08:00
Xinchen Hui
ccd4716ec7 year++ 2018-01-02 12:53:31 +08:00
Dmitry Stogov
d9f5ea691f zend_fcall_info_cache.initialized is removed (zend_fcall_info_cache is initialized if zend_fcall_info_cache.function_handler is set). 2017-12-27 15:15:03 +03:00
Xinchen Hui
4dfbfe93aa Use cheaper API 2017-12-18 11:55:14 +08:00
Markus Staab
5142a06506 Use known string "file" in stream layer 2017-12-16 13:25:05 +01:00
Dmitry Stogov
0f06df310c Turn "php_stream_wrapper"s into constants
Keep non-constant "php_stream_wrapper"s in API functions and callbacks for compatibility.
2017-12-14 22:46:22 +03:00
Dmitry Stogov
83e495e0fd Move constants into read-only data segment 2017-12-14 22:14:36 +03:00
Anatol Belski
98416a37f3 Put missing signature into header 2017-12-09 00:26:18 +01:00
Dmitry Stogov
6a9d2b2190 Cleanup type conversion 2017-12-07 19:24:55 +03:00
Dmitry Stogov
af7705bec2 Avoid strings duplication (zend_hash* and printf may work with non zero terminated strings) 2017-11-30 23:29:21 +03:00
Nikita Popov
26f8fc833b Enable and fix printf() format warnings
Add _unchecked() variants of zend_spprintf and zend_strpprintf for
cases where we specifically want to disable these checks, such as
use of %H.
2017-11-16 21:15:36 +01:00
Sara Golemon
fd463cfbad Merge branch 'PHP-7.2'
* PHP-7.2:
  Bugfix#75515 php://streams behaving greedily
2017-11-13 13:35:46 -05:00
Sara Golemon
0a45e8f096
Bugfix#75515 php://streams behaving greedily
5060fc23 attempted to fix #68948 by treating all non-uri streams
as non-blocking, however php://fd/* streams (which includes stdin)
may block if the other end of the IPC isn't finished.

This represents a partial revert to the pre RC6 state,
but includes an escape hatch for php://memory and php://temp
streams which are local to the current process.

This also restores stream_set_chunk_size test to previous state.
2017-11-13 09:40:34 -05:00
Sara Golemon
e36244e776 Merge branch 'PHP-7.2'
* PHP-7.2:
  Fixes #68948 related to a BC break introduced by #68532 fix.
2017-11-06 17:41:09 -05:00
Simon JAILLET
5060fc2349 Fixes #68948 related to a BC break introduced by #68532 fix. 2017-11-06 17:34:42 -05:00
Dmitry Stogov
468fd78bff Fixed memory leaks 2017-11-02 03:04:27 +03:00
Dmitry Stogov
67d5f39a47 Persistent resources are "thread-local".
Register persistent resources through new functions zend_register_persistent_resource()/zend_register_persistent_resource_ex().
2017-11-01 15:19:31 +03:00
Dmitry Stogov
8897c80956 Use interned strings for stream transports 2017-11-01 02:39:09 +03:00
Dmitry Stogov
bbfd0df9d3 Use interned strings for persistent stream wrappers and filters 2017-10-31 18:51:35 +03:00
Dmitry Stogov
8203a0668d Merge branch 'master' into rc_debug
* master:
  Use per-request heap instead of system one
  Extend zend_register_class_alias_ex() with additional argument to allow creating persistent or per-request aliases
  Makrk persistent resources and references with GC_PERSISTENT flag
2017-10-27 14:59:09 +03:00
Dmitry Stogov
cf67a421e9 Use per-request heap instead of system one 2017-10-27 14:45:54 +03:00
Dmitry Stogov
49ea143bbd Encapsulate reference-counting primitives.
Prohibit direct update of GC_REFCOUNT(), GC_SET_REFCOUNT(), GC_ADDREF() and GC_DELREF() shoukf be instead.
Added mactros to validate reference-counting (disabled for now).
These macros are going to be used to eliminate race-condintions during reference-counting on data shared between threads.
2017-10-27 01:28:58 +03:00
Kalle Sommer Nielsen
d3bc8beb4f Removed support for BeOS, development for BeOS was supported 17 years ago.
This patch however does not drop support for the BeOS compatible variant, Haiku, see Github PR #2697 which is currently a WiP

I intentionally left out some fragments for BeOS in the build system for that seems to be bundles
2017-08-29 22:03:56 +02:00
Adam Saponara
db96b7c245
Fix #75031: Support append mode in php://temp streams
This patch introduces a distinction between write mode and append
mode in `php://temp` and `php://memory` streams, achieving parity
with C stdio.
2017-08-04 12:43:49 +01:00
Anatol Belski
49d9b3013f Move cwd_state and path related routines to size_t
Having `int` there is no real profit in the size or speed, while unsigned
improves security and overall integration. ZPP supplied strings can
be then accepted directly and structs can be still handled with smaller
unsigned types for size reasons, which is safe. Yet some related places
are to go.

basic move tsrm_realpath_r to size_t

fix conditions and sync with affected places

touch ocurrences of php_sys_readlink usage

follow up on phar path handling

remove duplicated check

move zend_resolve_path and related pieces to size_t

touch yet resolve path related places

remove cast

missing pieces

missing piece

yet cleanups for php_sys_readlink for ssize_t

fix wrong return
2017-07-27 20:11:21 +02:00
Sara Golemon
bb02f99e71 Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Do not allow using traits/interfaces/abstract classes as stream wrappers
  Add oci8_failover.c to config.w32, follow up for commit 1b797f7a
2017-07-19 14:01:18 -04:00
Sara Golemon
a9e8239f45 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Do not allow using traits/interfaces/abstract classes as stream wrappers
2017-07-19 14:01:00 -04:00
Sara Golemon
c9fd093127
Do not allow using traits/interfaces/abstract classes as stream wrappers
Fixes https://bugs.php.net/bug.php?id=74951
2017-07-19 14:00:00 -04:00
Dmitry Stogov
6fcc7134f1 Keep resource of enclosing stream, because it may be referenced from other place(s).
This fixes valgrind warnings on Zend/tests/type_declarations/scalar_basic.phpt
2017-07-19 17:16:56 +03:00
Anatol Belski
2283b6ff53 eliminate casts 2017-07-10 15:48:54 +02:00
Anatol Belski
84079f4a1e cleanup casts 2017-07-09 15:31:05 +02:00
Anatol Belski
aaf09f7bdf eliminate casts 2017-07-09 15:11:02 +02:00
Tom Van Looy
04fb3f28ff Remove superfluous semicolons 2017-06-26 00:23:25 +02:00
Dmitry Stogov
f25ecdacf8 shutdown_executor() refactoring (reuse opcache fast request shutdown code) 2017-06-22 01:45:28 +03:00
Niklas Keller
bec91e1117 Use any TLS crypto method by default, don't use SSL 2017-06-10 17:31:24 -04:00
Anatol Belski
2111de0dd7 Merge branch 'PHP-7.1'
* PHP-7.1:
  Revert "Detect invalid port in xp_socket parse ip address"
  Revert "Follow up patch regarding bug #74216, see bug #74429"
2017-04-27 11:13:00 +02:00
Anatol Belski
392bcba58d Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Revert "Detect invalid port in xp_socket parse ip address"
  Revert "Follow up patch regarding bug #74216, see bug #74429"
2017-04-27 11:11:41 +02:00
Anatol Belski
09ef61e3ca Revert "Detect invalid port in xp_socket parse ip address"
This reverts commit bab0b99f37.
2017-04-27 02:49:12 +02:00
Anatol Belski
bf3e2dce7b Revert "Follow up patch regarding bug #74216, see bug #74429"
This reverts commit cda7dcf4ca.
2017-04-27 02:49:01 +02:00
Anatol Belski
bbf0a9d8a7 Merge branch 'PHP-7.1'
* PHP-7.1:
  Follow up patch regarding bug #74216, see bug #74429
2017-04-25 13:00:10 +02:00
Anatol Belski
faf19a7756 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Follow up patch regarding bug #74216, see bug #74429
2017-04-25 12:59:22 +02:00
Sara Golemon
cda7dcf4ca Follow up patch regarding bug #74216, see bug #74429
While the case in bug #74429 is not documented and is only worky due to
an implementation bug, the strength seems to breach some real world
apps. Given this patch doesn't impact the initial security fix for
bug #74216, it is reasonable to let the apps keep working. As mentioned
in the ticket, this behavior is a subject to change in future versions
and should not be abused.
2017-04-25 12:52:48 +02:00
Anatol Belski
bbe2a13395 Merge branch 'PHP-7.1'
* PHP-7.1:
  #74337 pointer returned by php_stream_fopen_tmpfile not validated in memory.c
2017-04-22 21:59:07 +02:00
Anatol Belski
91cb9a6ad1 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  #74337 pointer returned by php_stream_fopen_tmpfile not validated in memory.c
2017-04-22 21:58:10 +02:00
Anton Serbulov
793a8bd886 #74337 pointer returned by php_stream_fopen_tmpfile not validated in memory.c 2017-04-22 21:56:37 +02:00
Xinchen Hui
696bd37e67 Merge branch 'PHP-7.1'
* PHP-7.1:
  Fixed condition check
  Fixed condition check
  another place

Conflicts:
	ext/mcrypt/mcrypt.c
2017-04-10 14:49:13 +08:00
Xinchen Hui
65d77812fc Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed condition check
2017-04-10 14:47:42 +08:00
Xinchen Hui
4bebcb84ad Fixed condition check 2017-04-10 14:47:24 +08:00
Thomas Punt
9f08aff3fd Remove superfluous allocation checks around ZMM-based functions 2017-04-02 00:58:19 +02:00