Blame SOURCES/0002-Make-sure-strings-copied-by-strncpy-are-null-termina.patch

5c8506
From 695564da74fe7c95802f5bf59e442e23a2d7cbbf Mon Sep 17 00:00:00 2001
5c8506
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
5c8506
Date: Mon, 13 Aug 2018 14:39:43 +0200
5c8506
Subject: [PATCH 2/7] Make sure strings copied by strncpy are null-terminated
5c8506
MIME-Version: 1.0
5c8506
Content-Type: text/plain; charset=UTF-8
5c8506
Content-Transfer-Encoding: 8bit
5c8506
5c8506
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
5c8506
---
5c8506
 src/config.c  | 1 +
5c8506
 src/dial.c    | 3 +++
5c8506
 src/minicom.c | 3 +++
5c8506
 src/script.c  | 2 ++
5c8506
 src/updown.c  | 4 ++++
5c8506
 5 files changed, 13 insertions(+)
5c8506
5c8506
diff --git a/src/config.c b/src/config.c
5c8506
index 78b25aa..ea939c8 100644
5c8506
--- a/src/config.c
5c8506
+++ b/src/config.c
5c8506
@@ -88,6 +88,7 @@ void read_parms(void)
5c8506
   for (f = PROTO_BASE; f < MAXPROTO; f++) {
5c8506
     if (P_PNAME(f)[0] && P_PIORED(f) != 'Y' && P_PIORED(f) != 'N') {
5c8506
       strncpy(buf, P_PNAME(f) - 2, sizeof(buf));
5c8506
+      buf[sizeof(buf) - 1] = '\0';
5c8506
       strcpy(P_PNAME(f), buf);
5c8506
       P_PIORED(f) = 'Y';
5c8506
       P_PFULL(f) = 'N';
5c8506
diff --git a/src/dial.c b/src/dial.c
5c8506
index a90c1d2..a3337e5 100644
5c8506
--- a/src/dial.c
5c8506
+++ b/src/dial.c
5c8506
@@ -829,8 +829,11 @@ static int v1_read(FILE *fp, struct dialent *d)
5c8506
 
5c8506
   memcpy(d->username, v1.username, sizeof(v1) - offsetof(struct v1_dialent, username));
5c8506
   strncpy(d->name, v1.name, sizeof(d->name));
5c8506
+  d->name[sizeof(d->name) - 1] = '\0';
5c8506
   strncpy(d->number, v1.number, sizeof(d->number));
5c8506
+  d->number[sizeof(d->number) - 1] = '\0';
5c8506
   strncpy(d->script, v1.script, sizeof(d->script));
5c8506
+  d->script[sizeof(d->script) - 1] = '\0';
5c8506
   d->lastdate[0]=0;
5c8506
   d->lasttime[0]=0;
5c8506
   d->count=0;
5c8506
diff --git a/src/minicom.c b/src/minicom.c
5c8506
index 4eb47d4..876805a 100644
5c8506
--- a/src/minicom.c
5c8506
+++ b/src/minicom.c
5c8506
@@ -1208,6 +1208,7 @@ int main(int argc, char **argv)
5c8506
           break;
5c8506
         case 't': /* Terminal type */
5c8506
           strncpy(termtype, optarg, sizeof(termtype));
5c8506
+          termtype[sizeof(termtype) - 1] = '\0';
5c8506
 #ifdef __GLIBC__
5c8506
           /* Bug in older libc's (< 4.5.26 I think) */
5c8506
           if ((s = getenv("TERMCAP")) != NULL && *s != '/')
5c8506
@@ -1322,7 +1323,9 @@ int main(int argc, char **argv)
5c8506
     strncpy(homedir, pwd->pw_dir, sizeof(homedir));
5c8506
   else
5c8506
     strncpy(homedir, s, sizeof(homedir));
5c8506
+  homedir[sizeof(homedir) - 1] = '\0';
5c8506
   strncpy(username, pwd->pw_name, sizeof(username));
5c8506
+  username[sizeof(username) - 1] = '\0';
5c8506
 
5c8506
   /* Get personal parameter file */
5c8506
   snprintf(pparfile, sizeof(pparfile), "%s/.minirc.%s", homedir, use_port);
5c8506
diff --git a/src/script.c b/src/script.c
5c8506
index ee1284f..f7c4e3f 100644
5c8506
--- a/src/script.c
5c8506
+++ b/src/script.c
5c8506
@@ -1099,12 +1099,14 @@ int main(int argc, char **argv)
5c8506
 
5c8506
   if (argc > 2) {
5c8506
     strncpy(logfname, argv[2], sizeof(logfname));
5c8506
+    logfname[sizeof(logfname) - 1] = '\0';
5c8506
     if (argc > 3)
5c8506
       strncpy(homedir, argv[3], sizeof(homedir));
5c8506
     else if ((s = getenv("HOME")) != NULL)
5c8506
       strncpy(homedir, s, sizeof(homedir));
5c8506
     else
5c8506
       homedir[0] = 0;
5c8506
+    homedir[sizeof(homedir) - 1] = '\0';
5c8506
   }
5c8506
   else
5c8506
     logfname[0] = 0;
5c8506
diff --git a/src/updown.c b/src/updown.c
5c8506
index 726328e..54442bb 100644
5c8506
--- a/src/updown.c
5c8506
+++ b/src/updown.c
5c8506
@@ -386,6 +386,7 @@ void updown(int what, int nr)
5c8506
             do_log("%s", trimbuf);
5c8506
           } else if (!strncmp (buffirst, "Bytes", 5)) {
5c8506
             strncpy (xfrstr, buf, sizeof(xfrstr));
5c8506
+            xfrstr[sizeof(xfrstr) - 1] = '\0';
5c8506
           }
5c8506
           buffirst[0] = 0;
5c8506
           trimbuf[0] = 0;
5c8506
@@ -698,8 +699,11 @@ void runscript(int ask, const char *s, const char *l, const char *p)
5c8506
     }
5c8506
   } else {
5c8506
     strncpy(scr_user, l, sizeof(scr_user));
5c8506
+    scr_user[sizeof(scr_user) - 1] = '\0';
5c8506
     strncpy(scr_name, s, sizeof(scr_name));
5c8506
+    scr_name[sizeof(scr_name) - 1] = '\0';
5c8506
     strncpy(scr_passwd, p, sizeof(scr_passwd));
5c8506
+    scr_passwd[sizeof(scr_passwd) - 1] = '\0';
5c8506
   }
5c8506
   sprintf(scr_lines, "%d", (int) lines);  /* jl 13.09.97 */
5c8506
 
5c8506
-- 
5c8506
2.14.4
5c8506