Commit graph

273 commits

Author SHA1 Message Date
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
Christoph M. Becker
67e545f1bb
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #80880: SSL_read on shutdown, ftp/proc_open
2021-04-06 14:08:54 +02:00
Christoph M. Becker
de9734a5bb
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80880: SSL_read on shutdown, ftp/proc_open
2021-04-06 14:07:25 +02:00
Christoph M. Becker
9688071679
Fix #80880: SSL_read on shutdown, ftp/proc_open
When `SSL_read()` after `SSL_shutdown()` fails with `SSL_ERROR_SYSCALL`,
we should not warn about this, because it is likely caused by the peer
having closed the connection without having sent a close_notify
shutdown alert.

Signed-off-by: Christoph M. Becker <cmbecker69@gmx.de>

Closes GH-6803.
2021-04-06 14:03:19 +02: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
d1ac7e3ab1 Remove some unnecessary HAVE_EXTNAME guards
A recurring pattern in old extension: Putting the whole source
code behind HAVE_EXTNAME. This is pointless, as the code is only
compiled if the extension is enabled.

This removes a couple of them, but not all.
2020-09-07 11:05:07 +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
9bd648ba1e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #55857: ftp_size on large files
2020-06-23 16:02:19 +02:00
Christoph M. Becker
e7bbac9d11 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #55857: ftp_size on large files
2020-06-23 16:00:11 +02:00
Christoph M. Becker
e94126aac7 Fix #55857: ftp_size on large files
`atol()` returns a `long` which is not the same as `zend_long` on
LLP64; we use `ZEND_ATOL()` instead.

There is no need for a new test case, since filesize_large.phpt already
tests for that behavior; unfortunately, the FTP test suite relies on
`pcntl_fork()` and therefore cannot be run on Windows.
2020-06-23 15:57:24 +02:00