From 2b93b4bf38b7456be9c38259b8b3b6cff96595f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de>
Date: Sat, 29 Feb 2020 19:01:40 +0100
Subject: [PATCH 42/60] ftp: Fix strncpy misuse (leading to buffer overflow)

---
 ftp/ftp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ftp/ftp.c b/ftp/ftp.c
index 604d3e55..131f914d 100644
--- a/ftp/ftp.c
+++ b/ftp/ftp.c
@@ -175,9 +175,10 @@ hookup (char *host, int port)
     }
 
   if (res->ai_canonname)
-    strncpy (hostnamebuf, res->ai_canonname, sizeof (hostnamebuf));
+    strncpy (hostnamebuf, res->ai_canonname, sizeof (hostnamebuf) - 1);
   else
-    strncpy (hostnamebuf, rhost, sizeof (hostnamebuf));
+    strncpy (hostnamebuf, rhost, sizeof (hostnamebuf) - 1);
+  hostnamebuf[sizeof (hostnamebuf) - 1] = 0;
 
   hostname = hostnamebuf;
   free (rhost);
-- 
2.26.0.292.g33ef6b2f38

