git: 570869838f8b - main - libfetch: Plug connection leaks in FTP code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 30 Sep 2026 16:55:51 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=570869838f8bdaedb4c54953e80fe001a82190fd
commit 570869838f8bdaedb4c54953e80fe001a82190fd
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-30 16:55:23 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-09-30 16:55:23 +0000
libfetch: Plug connection leaks in FTP code
When setting up an FTP transfer, we need to dereference the cached
connection before returning after a failure.
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60017
---
lib/libfetch/ftp.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c
index 4c1a63d3da82..14abf97b827f 100644
--- a/lib/libfetch/ftp.c
+++ b/lib/libfetch/ftp.c
@@ -1053,7 +1053,7 @@ ftp_cached_connect(struct url *url, struct url *purl, const char *flags)
/* connect to server */
if ((conn = ftp_connect(url, purl, flags)) == NULL)
return (NULL);
- if (cached_connection)
+ if (cached_connection != NULL)
ftp_disconnect(cached_connection);
cached_connection = fetch_ref(conn);
memcpy(&cached_host, url, sizeof(*url));
@@ -1100,6 +1100,7 @@ ftp_request(struct url *url, const char *op, struct url_stat *us,
struct url *purl, const char *flags)
{
conn_t *conn;
+ FILE *f;
int oflag;
/* check if we should use HTTP instead */
@@ -1144,9 +1145,12 @@ ftp_request(struct url *url, const char *op, struct url_stat *us,
oflag = O_RDONLY;
/* initiate the transfer */
- return (ftp_transfer(conn, op, url->doc, oflag, url->offset, flags));
-
+ f = ftp_transfer(conn, op, url->doc, oflag, url->offset, flags);
+ if (f == NULL)
+ goto errsock;
+ return (f);
errsock:
+ fetch_deref(conn);
ftp_disconnect(conn);
return (NULL);
}