Skip to content

ext/ftp: avoid one-byte out-of-bounds write in ftp_readline()#102

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
ftp-readline-oob
Closed

ext/ftp: avoid one-byte out-of-bounds write in ftp_readline()#102
iliaal wants to merge 1 commit into
PHP-8.4from
ftp-readline-oob

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner

The bug80901 fix (09696ee) terminates an over-long server 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. Reserving the final byte keeps the terminator inside inbuf. The overwrite is intra-struct (same allocation) so neither valgrind nor ASAN flags it. The existing bug80901 test exercises this exact path (a 4096-byte SYST reply); its expected output drops from 4096 to 4095 visible chars because the terminator now legitimately occupies the last slot instead of overflowing.

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).
@iliaal iliaal force-pushed the ftp-readline-oob branch from 31dc010 to 4395f61 Compare June 21, 2026 01:22
@iliaal

iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22377.

@iliaal iliaal closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant