Repository navigation
Fix double free in ext/ftp data_accept() on accept failure - #24339
Closed
alepacheco wants to merge 2 commits into
Closed
alepacheco wants to merge 2 commits into
alepacheco wants to merge 2 commits into
Conversation
When the server never opens the active-mode data connection, my_accept() fails and data_accept() frees the databuf_t. ftp_getdata() has already stored it in ftp->data, so the caller's bail path then runs data_close(), which frees it a second time. This affects ftp_get(), ftp_put(), ftp_append(), ftp_nb_get(), ftp_nb_put() and the listing functions. data_accept() does not own the buffer: leave it in ftp->data and let data_close() release it, as the SSL failure paths in data_accept() already do.
…out.phpt musl and FreeBSD report "Operation timed out", glibc "Connection timed out".
Contributor
Author
|
Thanks for the review! The WINDOWS_X64_ZTS failure is the proc_open_null/proc_open_redirect pair that fails on other PHP-8.4 PRs too; nothing in ext/ftp. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In active mode, when the server never opens the data connection,
my_accept()fails anddata_accept()frees thedatabuf_t.ftp_getdata()has already stored that buffer inftp->data, so the caller'sbail:path runsdata_close(ftp)and frees it again. Every transfer and listing function that goes throughdata_accept()is affected (ftp_get(),ftp_put(),ftp_append(),ftp_nb_get(),ftp_nb_put(),ftp_nlist()/ftp_rawlist()/ftp_mlsd()).The SSL failure paths in
data_accept()already return without freeing and leave the cleanup todata_close(). This makes the accept failure path do the same, sodata_close()is the only place that frees a publishedftp->data.The test adds a
server.incfile name that answersRETRwith 150 but never connects back, and checks thatftp_get()andftp_nb_get()both fail cleanly after the timeout.Targeting PHP-8.4 as the oldest branch with the bug in active support.