Skip to content

ext/ftp: fix off-by-one terminator write in ftp_readline()#22377

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:ftp-readline-oob
Open

ext/ftp: fix off-by-one terminator write in ftp_readline()#22377
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:ftp-readline-oob

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

A response that fills FTP_BUFSIZE with no CR/LF makes ftp_readline() write its NUL terminator one byte past inbuf, into the adjacent ftpbuf_t::extra field. Reserve the final byte for the terminator so it always lands inside inbuf. Regression from the bug80901 fix (09696ee); the SYST reply in that test is now 4095 visible characters.

The bug80901 fix (09696ee) terminates an over-long response with
*data = 0, but when the line fills the whole FTP_BUFSIZE inbuf without a
CR/LF, data points at inbuf[FTP_BUFSIZE] and the terminator is written one
byte past the buffer, into the adjacent ftpbuf_t::extra field. Reserve the
final byte for the terminator so it always lands inside inbuf. A
buffer-filling response loses its last character (bug80901's SYST reply is
now 4095 visible chars, with the terminator taking the 4096th slot).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant