Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 662684 - net-ftp/ftp- patch 070_all_segv.patch causes segfault
Summary: net-ftp/ftp- patch 070_all_segv.patch causes segfault
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
Keywords: PullRequest
Depends on:
Reported: 2018-08-02 22:18 UTC by Hank Leininger
Modified: 2021-09-28 03:35 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Hank Leininger 2018-08-02 22:18:41 UTC
The ftp client will segv when connecting to a server that immediately issues a 421 response:

term1$ echo "421 Service not available." | ncat -n -v -l
Ncat: Listening on

term2$ ftp -d -v 31337
Connected to
421 Service not available.
Segmentation fault (core dumped)

gdb shows it dying in fclose; strace shows two calls to fclose in a row.

net-ftp/ftp applies patch sets from Debian and then from Gentoo.  I found that if I removed the second chunk of 070_all_segv.patch from Gentoo's netkit-ftp-0.17-patches-2.tar.bz2, the crash goes away:

$ ftp 31337
Connected to
421 Service not available.

That patch hunk is in ftp/ftp.c:

@@ -529,6 +531,10 @@
+                       if (cout) {
+                               fclose(cout);
+                               cout = NULL;
+                       }
                return (n - '0');

...And it is modifying the behavior at the end of getreply(), specifically, how it handles 421 responses.  With that removed, there's only one fclose() call.  I suspect that this error path is (now?) properly handled and the patch hunk can be dropped.
Comment 1 Hank Leininger 2020-12-28 23:19:43 UTC
Ping, this segv still occurs, 2+ years later.
Comment 2 Larry the Git Cow gentoo-dev 2021-09-28 03:35:09 UTC
The bug has been closed via the following commit(s):

commit 74fca1f794ce6bf84cb6354cc31d5f307508e155
Author:     Hank Leininger <>
AuthorDate: 2020-12-29 01:12:10 +0000
Commit:     Sam James <>
CommitDate: 2021-09-28 03:34:53 +0000

    net-ftp/ftp: version bump, EAPI bump, fix segv
    Sync to a more recent Debian version
    (netkit-ftp-ssl_0.17.34+0.2-5.1.dsc), and fix longstanding segv
    when the server goes away. Updated Gentoo patches for the current
    Debian version. Tested with gcc-10.
    Signed-off-by: Hank Leininger <>
    Package-Manager: Portage-3.0.12, Repoman-3.0.2
    Signed-off-by: Sam James <>

 net-ftp/ftp/Manifest                   |  2 ++
 net-ftp/ftp/ftp- | 66 ++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)