Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/mount_portal properly terminate a buffer after strncpy().



details:   https://anonhg.NetBSD.org/src/rev/3cc4f1c89dee
branches:  trunk
changeset: 961201:3cc4f1c89dee
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Apr 12 09:18:14 2021 +0000

description:
properly terminate a buffer after strncpy().

diffstat:

 sbin/mount_portal/pt_filter.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r 1234418284ea -r 3cc4f1c89dee sbin/mount_portal/pt_filter.c
--- a/sbin/mount_portal/pt_filter.c     Mon Apr 12 09:17:48 2021 +0000
+++ b/sbin/mount_portal/pt_filter.c     Mon Apr 12 09:18:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pt_filter.c,v 1.12 2020/05/14 08:34:17 msaitoh Exp $   */
+/*     $NetBSD: pt_filter.c,v 1.13 2021/04/12 09:18:14 mrg Exp $       */
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: pt_filter.c,v 1.12 2020/05/14 08:34:17 msaitoh Exp $");
+__RCSID("$NetBSD: pt_filter.c,v 1.13 2021/04/12 09:18:14 mrg Exp $");
 #endif                         /* not lint */
 
 #include <stdio.h>
@@ -65,7 +65,8 @@
        if (tempbuff == NULL)
                err(1, NULL);
 
-       strncpy(tempbuff, cmdv[0], n);
+       strncpy(tempbuff, cmdv[0], n - 1);
+       tempbuff[n - 1] = '\0';
        for (i = 1; cmdv[i]; i++) {
                strncat(tempbuff, " ", n - strlen(tempbuff));
                strncat(tempbuff, cmdv[i], n - strlen(tempbuff));



Home | Main Index | Thread Index | Old Index