1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

282 Commits

Author SHA1 Message Date
Niels Dossche
64b30cee76 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20240: FTP with SSL: ftp_fput(): Connection timed out on successful writes
2025-10-26 23:40:01 +01:00
Niels Dossche
6bcc4e2c09 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20240: FTP with SSL: ftp_fput(): Connection timed out on successful writes
2025-10-26 23:39:56 +01:00
Niels Dossche
6dab33a438 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-20240: FTP with SSL: ftp_fput(): Connection timed out on successful writes
2025-10-26 23:39:02 +01:00
Niels Dossche
8761c4e507 Fix GH-20240: FTP with SSL: ftp_fput(): Connection timed out on successful writes
Looking at the strace, the timeout is only 1s which may be too low
anyway for checking for a response, but some servers also don't end up
replying finally anyway and close the connection already.

`data_available` was originally used for non-blocking downloads/uploads
and then reused for the shutdown sequence, but its error handling was
never adjusted to be silent.

Closes GH-20294.
2025-10-26 23:38:09 +01:00
Tim Düsterhus
aa90372428 ftp: Use return true / return false for functions returning bool
Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
2025-09-24 18:51:40 +02:00
Tim Düsterhus
9a36e513a6 ftp: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Niels Dossche
93b9808004 Merge branch 'PHP-8.4'
* PHP-8.4:
  NEWS for hrtime in FTP and standard
  Handle broken hrtime in ftp
  Fix arginfo/zpp violation if zend_hrtime is not available
2025-07-25 12:05:17 +02:00
Niels Dossche
802e348b49 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  NEWS for hrtime in FTP and standard
  Handle broken hrtime in ftp
  Fix arginfo/zpp violation if zend_hrtime is not available
2025-07-25 12:05:12 +02:00
Niels Dossche
beeeee2978 Handle broken hrtime in ftp
Part of GH-19210.

Closes GH-19219.
2025-07-25 11:56:30 +02:00
Gina Peter Banyard
8033b058a9 ext/ftp: Remove output field of ftpbuf_t struct
It was only used once, and removing it reduces the size of a userland FTP object by 4096 bytes
2025-04-03 22:47:13 +01:00
Gina Peter Banyard
96cf1b5a9f ext/ftp: Use size_t type instead of int type 2025-04-03 22:47:13 +01:00
Gina Peter Banyard
7fcdf1cfa2 ext/ftp: Use zend_result type instead of int type 2025-04-03 22:47:13 +01:00
Gina Peter Banyard
169573bcb5 ext/ftp: Use bool type instead of int type 2025-04-03 22:47:13 +01:00
Gina Peter Banyard
114a8ffb9d ext/ftp: Mark static functions as such
Removing missleading comment
2025-04-03 22:47:13 +01:00
Gina Peter Banyard
51fa97fb44 ext/ftp: Normalize coding style 2025-04-03 22:47:13 +01:00
Gina Peter Banyard
7fb8db014e ext/ftp: Voidify ftp_close() 2025-04-03 22:47:13 +01:00
Niels Dossche
e90243a640 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16800: ftp functions can abort with EINTR
2025-01-03 12:31:08 +01:00
Niels Dossche
412a6b2e08 Fix GH-16800: ftp functions can abort with EINTR
This adds wrappers around recv(), send(), and php_pollfd_for_ms() to
handle EINTR.

This is a bit hard to test on its own, but it is testable manually using
the following script:
```php
pcntl_signal(SIGUSR1, function() {
    var_dump(func_get_args());
}, false);

var_dump(getmypid());
sleep(10);

$ftp = ftp_connect('127.0.0.1');
ftp_login($ftp, 'user', 'pass');
ftp_put($ftp, 'testfile', 'testfile');
```

in combination with an infinite while loop that sends SIGUSR1 to the
process.

Closes GH-17327.
2025-01-03 12:30:43 +01:00
Arnaud Le Blanc
11accb5cdf Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Niels Dossche
55dfd45581 Fix bug #63937: Upload speed 10 times slower with PHP (#13041)
There are two slow parts in the upload logic:
- Reading from the input stream character by character
- Checking each character one by one to normalize line endings

First of all, the line normalization isn't necessary for binary
transfers, so we can use a simple read while loop to read bytes into the
transfer buffer.

Second, for the ASCII transfer where we do have to normalize line
endings, we can be smarter than reading one character at a time. There's
a php_stream_get_line() function that we can repurpose if the flags for
the stream are set up properly.

This patch implements these fixes.

Results: I tested this on an 850 MiB file, transferring this to an FTP
server running locally.

Results before patch:
Binary/ASCII transfer (same code path): 8.21s

Results after patch:
Binary transfer: 0.65s
ASCII transfer: 0.74s

Further improvement is probably possible by having a larger send buffer.
2024-04-13 01:39:31 +02:00
Ayesh Karunaratne
3de3e137bf ext/openssl: Bump minimum required OpenSSL version to 1.1.1
Bumps the minimum required OpenSSL version from 1.0.2 to 1.1.1.

OpenSSL 1.1.1 is an LTS release, but has reached[^1] EOL from upstream. However, Linux distro/OS vendors
continue to ship OpenSSL 1.1.1, so 1.1.1 was picked as the minimum. The current minimum 1.0.2 reached
EOL in 2018.

Bumping the minimum required OpenSSL version makes it possible for ext-openssl to remove a bunch of
conditional code, and assume that TLS 1.3 (shipped with OpenSSL 1.1.1) will be supported everywhere.

 - Debian buster: 1.1.1[^2]
 - Ubuntu 20.04: 1.1.1[^3]
 - CentOS/RHEL 7: 1.0.2
 - RHEL 8/Rocky 8/EL 8: 1.1.1
 - Fedora 38: 3.0.9 (`openssl11` provides OpenSSL 1.1 as well)

RHEL/CentOS 7 reaches EOL mid 2024, so for PHP 8.4 scheduled towards the end of this year, we can safely
bump the minimum OpenSSL version.

[^1]: https://www.openssl.org/blog/blog/2023/03/28/1.1.1-EOL/index.html
[^2]: https://packages.debian.org/buster/libssl-dev
[^3]: https://packages.ubuntu.com/focal/libssl-dev
2024-03-23 15:12:06 +00:00
Jorg Adam Sowa
e630aacf79 Remove HAVE_INET_PTON (#13410) 2024-02-21 00:43:56 +00:00
Niels Dossche
d751e61504 Struct-pack stream-related data in ftpbuf (#12877) 2023-12-06 04:39:00 +00:00
Ilija Tovilo
289073b452 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix compilation of ftp without openssl
2023-12-05 11:59:04 +01:00
Ilija Tovilo
b4b157edab Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix compilation of ftp without openssl
2023-12-05 11:56:15 +01:00
Ilija Tovilo
4f934cb7f7 Fix compilation of ftp without openssl
Closes GH-12866
2023-12-05 11:55:44 +01:00
Niels Dossche
f3cddbb831 Remove redundant assignments to ftp->data
ftp_getdata() already does this.

Closes GH-12849.
2023-12-03 00:59:17 +01:00
Niels Dossche
35cf7abec7 Cleanup internal data_close API
This always returns NULL. Also passing in data is not necessary as it is
always equal to ftp->data.
2023-12-03 00:58:50 +01:00
Niels Dossche
f601963d4f Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-9348: FTP & SSL session reuse
2023-12-03 00:52:15 +01:00
Niels Dossche
addb6e463a Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-9348: FTP & SSL session reuse
2023-12-03 00:52:08 +01:00
Niels Dossche
ac8a58fab1 Fix GH-9348: FTP & SSL session reuse
The issue referenced here doesn't contain a reproducer, but I recently
received an email of a user with the exact same problem. I was able to
recreate the scenario locally using vsftpd and setting
`require_ssl_reuse=YES` in the vsftpd configuration.

It turns out that our session resumption code is broken. It only works a
single time: the first time a data connection opens. Subsequent data
connections fail to reuse the session. This is because on every data
connection a new session is negotiated, but the current code always
tries to reuse the (stale) session of the control connection.

To fix this, we use SSL_CTX_sess_set_new_cb() to setup a callback that
gets called every time a new session is negotiated. We take a strong
reference using SSL_get1_session() and store it in the ftpbuf_t struct.
Every time we open a data connection we'll take that session.
This works because every control connection has at most a single
associated data connection.

Also disable internal session caching storage to not fill the cache up
with useless sessions.

There is no phpt for this because PHP does not support enforcing SSL
session reuse.
It is however testable manually by setting up vsftpd and setting the
`require_ssl_reuse=YES` function from before.

Closes GH-12851.
2023-12-03 00:47:33 +01:00
David CARLIER
931a8b0739 inet_ntop requirement check at configure time instead (#12700) 2023-11-17 16:01:46 +00:00
David Carlier
44f9c226aa following-up on GH-12551: removing inet_ntoa usage
Close GH-12554
2023-11-06 12:05:56 +00:00
Niels Dossche
eacfbd9ae8 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10562: Memory leak and invalid state with consecutive ftp_nb_fget
2023-07-07 18:01:53 +02:00
Niels Dossche
4dcb5af3a9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10562: Memory leak and invalid state with consecutive ftp_nb_fget
2023-07-07 17:59:00 +02:00
Niels Dossche
c962a96c34 Fix GH-10562: Memory leak and invalid state with consecutive ftp_nb_fget
When the user does not fully consume the data stream, but instead opens
a new one, a memory leak occurs. Moreover, the state is invalid: when
more commands arrive they'll be handled out-of-sync because the state of
the client does not match what the server is doing.
This leads to all sorts of weirdness, for example:
  Warning: ftp_nb_fget(): OK.

Fix it by gracefully closing the old data stream when a new data stream
is started.

Closes GH-11606.
2023-07-07 17:55:53 +02:00
George Peter Banyard
d5ad75108e More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Niels Dossche
57442f8f35 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10521: ftp_get/ftp_nb_get resumepos offset is maximum 10GB
2023-03-20 23:27:46 +01:00
Niels Dossche
301418284d Fix GH-10521: ftp_get/ftp_nb_get resumepos offset is maximum 10GB
The char arrays were too small for a long on 64-bit systems, which
resulted in cutting off the string at the end with a NUL byte. Use a
size of MAX_LENGTH_OF_LONG to fix this issue instead of a fixed size
of 11 chars.

Closes GH-10525.
2023-03-20 23:20:21 +01:00
Jihwan Kim
af20923a0f Fix datetime format string to follow POSIX spec in ftp_mdtm()
Closes GH-8259
2022-05-24 19:23:47 -05:00
Nikita Popov
efbb2198d4 Return value from ZEND_ATOL
Instead of assigning it as part of the macro itself, which makes
usage quite awkward.
2021-07-12 16:51:24 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02: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
Christoph M. Becker
895185e5ea Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #79100: Wrong FTP error messages
2021-05-03 15:25:17 +02:00
Christoph M. Becker
c2a06f5d9a Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #79100: Wrong FTP error messages
2021-05-03 15:24:17 +02:00
Christoph M. Becker
42c72ef463 Fix #79100: Wrong FTP error messages
First we need to properly clear the `inbuf`, what is an amendment to
commit d2881adcbc[1].

Then we need to report `php_pollfd_for_ms()` failures right away; just
setting `errno` does not really help, since at least in some cases it
would have been overwritten before we actually could check it.  We use
`php_socket_strerror()` to get a proper error message, and define
`ETIMEDOUT` to the proper value on Windows; otherwise we catch the
definition in errno.h, which is not compatible with WinSock.  The
proper solution for this issue would likely be to include something
like ext/sockets/windows_common.h.

Finally, we ensure that we only report warnings using `inbuf`, if it is
not empty.

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

Closes GH-6718.
2021-05-03 15:19:57 +02:00
Christoph M. Becker
c0ae3a7fb7 Fix #80901: Info leak in ftp extension
We ensure that inbuf is NUL terminated on `ftp_readline()` failure.

Closes GH-6894.
2021-04-26 15:07:08 +02:00
Christoph M. Becker
5d7219dce6 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #80901: Info leak in ftp extension
2021-04-26 14:46:43 +02:00
Christoph M. Becker
33d49551d1 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80901: Info leak in ftp extension
2021-04-26 14:45:55 +02:00
Christoph M. Becker
09696eee9d Fix #80901: Info leak in ftp extension
We ensure that inbuf is NUL terminated on `ftp_readline()` failure.

Closes GH-6894.
2021-04-26 14:23:04 +02:00