[php-src] PHP-8.6: `php_ftp_fopen_connect()`: Confirm no extra commands are smuggled in (#23856)

From: Date: Mon, 19 Oct 2026 19:02:59 +0000
Subject: [php-src] PHP-8.6: `php_ftp_fopen_connect()`: Confirm no extra commands are smuggled in (#23856)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142463@lists.php.net to get a copy of this message
Author: Daniel Scherzer (DanielEScherzer) Committer: GitHub (web-flow) Pusher: DanielEScherzer Date: 2026-10-19T12:02:55-07:00 Commit: https://github.com/php/php-src/commit/df30187db9808c4c68a41255b7c73d427b581b5b Raw diff: https://github.com/php/php-src/commit/df30187db9808c4c68a41255b7c73d427b581b5b.diff php_ftp_fopen_connect(): Confirm no extra commands are smuggled in (#23856) Add a debug-only assertion that the parsed resource path has no remaining "\r\n" substrings which would separate commands. Intended as a hardening measure - at the moment all supported parsing backends handle included "\r\n" properly. Changed paths: M ext/standard/ftp_fopen_wrapper.c Diff: diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index cf529e40085b..97879a5c7000 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -142,6 +142,14 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char return NULL; } + /* Searching for a substring is a bit expensive, and this is just a + * hardening assertion to confirm php_uri_parse_to_struct() stripped any + * CRLF sequence, only run in debug mode. */ +#if ZEND_DEBUG + char *pos = strstr(ZSTR_VAL(resource->path), "\r\n"); + ZEND_ASSERT(pos == NULL); +#endif + use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 3) && ZSTR_VAL(resource->scheme)[3] == 's'; /* use port 21 if one wasn't specified */

« previous php.cvs (#142463) next »