Commit graph

792 commits

Author SHA1 Message Date
George Peter Banyard
1ff59b9ad9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix off-by-one bug when truncating tempnam prefix
2023-08-08 09:51:02 +01:00
Athos Ribeiro
cbfd73765a Fix off-by-one bug when truncating tempnam prefix
The tempnam documentation currently states that "Only the first 63
characters of the prefix are used, the rest are ignored". However when
the prefix is 64 characters-long, the current implementation fails to
strip the last character, diverging from the documented behavior. This
patch fixes the implementation so it matches the documented behavior for
that specific case where the prefix is 64 characters long.

Closes GH-11870

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-08-08 09:46:27 +01:00
Ilija Tovilo
de9b3f648c
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex
2023-04-30 13:37:08 +02:00
Ilija Tovilo
8bf2d587d7
Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex
Otherwise we can get open_basedir warnings from the stat call while still
performing the actual copy.

Fixes GH-11138
Closes GH-11156
2023-04-30 13:36:15 +02:00
Ilija Tovilo
c5fe6c2eb9
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix buffer-overflow in php_fgetcsv() with \0 delimiter and enclosure
2023-03-25 17:43:07 +01:00
Ilija Tovilo
57029ce92e
Fix buffer-overflow in php_fgetcsv() with \0 delimiter and enclosure
Fixes oss-fuzz #57392
Closes GH-10923
2023-03-25 17:42:39 +01:00
Máté Kocsis
c573b8228a
Declare ext/standard constants in stubs - part 2 (#9426) 2022-08-26 14:40:48 +02:00
George Peter Banyard
4ccf0b0181
Make php_fgetcsv() return a HashTale instead of in-out zval param (#8936)
Also refactor what happens on an empty line to return NULL instead of setting the array to [NULL] which makes no design sense at all.
However, as this is the current behaviour create a BC Shim inline function to recreate this weird HashTable in the functions which currently use this API
2022-07-08 12:11:05 +01:00
Max Kellermann
6beee1a5bb
Disable the read buffer in file_get_contents()
The read buffer is useless here, it only hurts performance.

Closes GH-8547.
2022-05-16 16:21:29 +02:00
George Peter Banyard
5171cb435a Fix [-Wundef] warnings in standard extension 2022-04-01 15:48:41 +01:00
Aliaksandr Bystry
52e7e0f521 Fix bug #66588: SplFileObject::fgetcsv incorrectly returns a row on premature EOF
Make sure the behavior is the same regardless of whether there is
a trailing newline and whether the input is a stream or not.

Closes GH-7539.
2021-10-01 16:21:26 +02:00
Tim Starling
c96be7b8f2 Use ASCII lower case for misc case folding
Use ASCII case conversion instead of locale-dependent case conversion in
the following places:

* grapheme_stripos() and grapheme_strripos() in the "fast" path
* ldap_get_entries()
* oci_pconnect() for case folding of parameters when constructing a key
  into the connection or session pool
* SoapClient: case folding of function names
* get_meta_tags(): case conversion of property names
* http stream wrapper: header names
* phpinfo(): anchor names
* php_verror(): docref URLs
* rfc1867.c: Content-Type boundary parameter name
* streams.c: stream protocol names

Using locale-dependent case folding for these cases is either
unnecessary or actively incorrect. These functions could have
misbehaved when used with certain locales (e.g. Turkish).

Closes GH-7511.
2021-09-24 09:20:08 +02:00
Nikita Popov
14f599ea7d Use zend_long for resource ID
Currently, resource IDs are limited to 32-bits. As resource IDs
are not reused, this means that resource ID overflow for
long-running processes is very possible.

This patch switches resource IDs to use zend_long instead, which
means that on 64-bit systems, 64-bit resource IDs will be used.
This makes resource ID overflow practically impossible.

The tradeoff is an 8 byte increase in zend_resource size.

Closes GH-7436.
2021-08-31 14:58:59 +02:00
Ikko Ashimine
6e5771148d Fix typo in file.c
apostrohpe -> apostrophe
2021-08-25 09:51:32 +02:00
Nikita Popov
6e20f0f3a2 Returned interned string from fgetc()
Make use of single-character interned strings.
2021-08-16 11:15:23 +02:00
Nikita Popov
232aa34b9f Deprecate auto_detect_line_endings
Part of https://wiki.php.net/rfc/deprecations_php_8_1.
2021-07-09 10:05:57 +02:00
Nikita Popov
92f6e21523 Deprecate FILE_BINARY and FILE_TEXT constants
These constants have no effect.

Part of https://wiki.php.net/rfc/deprecations_php_8_1.
2021-07-08 15:34:51 +02:00
Nikita Popov
076fbd360a Minor fgetcsv cleanup
Reduce some variable scopes.
2021-07-06 12:37:22 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
George Peter Banyard
aca6aefd85
Remove 'register' type qualifier (#6980)
The compiler should be smart enough to optimize this on its own
2021-05-14 13:38:01 +01:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
David Gebler
cbcfd86026 Add fsync() and fdatasync() functions
fsync is a straightforward wrapper around the same C function
(implemented on Windows API as _commit() with identical signature).

From the man pages:

    fsync() transfers ("flushes") all modified in-core data of (i.e.,
    modified buffer cache pages for) the file referred to by the file
    descriptor fd to the disk device (or other permanent storage
    device) so that all changed information can be retrieved even if
    the system crashes or is rebooted.  This includes writing through
    or flushing a disk cache if present.  The call blocks until the
    device reports that the transfer has completed.

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

Closes GH-6650.
2021-04-13 16:09:22 +02:00
George Peter Banyard
5caaf40b43
Introduce pseudo-keyword ZEND_FALLTHROUGH
And use it instead of comments
2021-04-07 00:46:29 +01:00
George Peter Banyard
8560d168d3
Align types with the output of zend_hash_num_elements() 2021-03-29 14:20:22 +01:00
Cameron Hall
5b29eba7ca Fix #42357: fputcsv() has an optional parameter for line endings
fputcsv does not terminate lines correctly as per RFC 41801[1]. After adding a new parameter fputcsv may now use a user defined line ending,. In order to maintain backwards compatibility fputcsv() still terminates lines with "\n" by default.

Also fixes: #46367[2], #62770[3]
Ref: #42357[4]

[1] <https://tools.ietf.org/html/rfc4180>
[2] <https://bugs.php.net/bug.php?id=46367>
[3] <https://bugs.php.net/bug.php?id=62770>
[4] <https://bugs.php.net/bug.php?id=42357>
2021-03-29 13:34:38 +01:00
Dmitry Stogov
13e4ce386b Improve SPL directory and stat() cache using zend_srting* instead of char* 2021-02-26 02:28:46 +03:00
Christoph M. Becker
eea4aac1a0 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #80654: file_get_contents() maxlen fails above (2**31)-1 bytes
2021-02-01 13:01:27 +01:00
Christoph M. Becker
766d5846b1 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80654: file_get_contents() maxlen fails above (2**31)-1 bytes
2021-02-01 13:00:22 +01:00
Christoph M. Becker
7e9479083d Fix #80654: file_get_contents() maxlen fails above (2**31)-1 bytes
We remove the arbitrary restriction to `INT_MAX`; it is superfluous on
32bit systems where `ZEND_LONG_MAX == INT_MAX` anyway, and not useful
on 64bit systems, where larger files should be readable, if the
`memory_limit` is large enough.

Closes GH-6648.
2021-02-01 12:57:40 +01:00
Nikita Popov
9be0ee4309 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #42560
2021-01-19 11:44:49 +01: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
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

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

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

Also drop the unused convert_to_explicit_type macros.
2021-01-14 12:11:11 +01:00
Nikita Popov
625d8463a4 Consistent error handling for fgetcsv/fputcsv
Normalize the behavior between the file functions and those on
SplFileObject.

Be consistent about throwing regardless of whether the delimiter etc
is empty or has too many characters. I don't think it's worthwhile
to distinguish these cases.

Back when we looked into this originally, there was some hope that
we might want to add support for multiple-character delimiter etc,
but after a cursory look, I really don't think this is going to
happen (for fputcsv maybe, but for fgetcsv this just makes an already
broken function much more complicated.)

Closes GH-6188.
2020-09-23 10:11:04 +02:00
Ikko Ashimine
8f3a38d927 Fixed minor typo in comment
Initiailize -> Initialize

Closes GH-6181.
2020-09-22 09:10:23 +02:00
Máté Kocsis
e950ca13ea
Consolidate the usage of "either" and "one of" in error messages
Closes GH-6173
2020-09-20 19:41:47 +02:00
Máté Kocsis
c37a1cd650
Promote a few remaining errors in ext/standard
Closes GH-6110
2020-09-15 14:26:16 +02:00
Máté Kocsis
2c96780e1c
Fix UNKNOWN default values in ext/standard
Closes GH-6026
2020-09-07 18:58:11 +02:00
George Peter Banyard
7805b97720 Extract common flock code
As SPL is currently a copie of the code in file.c

Closes GH-6069
2020-09-04 14:29:31 +02:00
George Peter Banyard
430b3ac7df Refactor parts of SPL Dir/SplFileObject
This fixes a way it was possible to trigger an Internel Error
by disabling function (via the INI setting) when SPL was acting
as a proxy to the function call.

Fix flock_compat layer as it needs to used in SPL now.

Use macro to check if object is initialized

Closes GH-6014
2020-09-03 14:23:18 +02:00
Máté Kocsis
af80d8a14e
Add more argument types to stubs
Closes GH-5943
2020-08-07 12:35:30 +02:00
Nikita Popov
3bb1830369 Reapply "Explicitly validate popen mode"
To avoid behavior differences due to libc. This time with the
check only for the non-win32 case, as Windows support additional
modifiers here (t/b).
2020-08-07 10:33:27 +02:00
Nikita Popov
7c8467562d Revert "Explicitly validate popen mode"
This reverts commit ab36540bdd.

Causes a test failure on Windows.
2020-08-06 21:53:13 +02:00
Nikita Popov
ab36540bdd Explicitly validate popen mode
To avoid behavior differences due to libc.
2020-08-06 10:26:46 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Christoph M. Becker
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
twosee
7d6a0ba808 Fix expression warnings and break warnings
Close GH-5675.
2020-06-07 10:41:11 +02:00