Source-Changes-HG archive

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

[src/trunk]: src/tests/net ifr_name is nul terminated. make it so.



details:   https://anonhg.NetBSD.org/src/rev/1e3a510cf047
branches:  trunk
changeset: 460223:1e3a510cf047
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Oct 13 07:46:16 2019 +0000

description:
ifr_name is nul terminated.  make it so.

diffstat:

 tests/net/can/h_canutils.c     |  10 ++++++----
 tests/net/if_vlan/siocXmulti.c |   3 ++-
 2 files changed, 8 insertions(+), 5 deletions(-)

diffs (50 lines):

diff -r 6622dad0bdb0 -r 1e3a510cf047 tests/net/can/h_canutils.c
--- a/tests/net/can/h_canutils.c        Sun Oct 13 07:44:51 2019 +0000
+++ b/tests/net/can/h_canutils.c        Sun Oct 13 07:46:16 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_canutils.c,v 1.3 2017/05/28 13:55:07 kre Exp $       */
+/*     $NetBSD: h_canutils.c,v 1.4 2019/10/13 07:46:16 mrg Exp $       */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: h_canutils.c,v 1.3 2017/05/28 13:55:07 kre Exp $");
+__RCSID("$NetBSD: h_canutils.c,v 1.4 2019/10/13 07:46:16 mrg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -70,14 +70,16 @@
        }
 
        memset(&ifr, 0, sizeof(ifr));
-       strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+       strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
+       ifr.ifr_name[IFNAMSIZ - 1] = '\0';
 
        if ((rv = rump_sys_ioctl(s, SIOCIFCREATE, &ifr)) < 0) {
                atf_tc_fail_errno("if config create");
        }
 
        memset(&ifr, 0, sizeof(ifr));
-       strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+       strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
+       ifr.ifr_name[IFNAMSIZ - 1] = '\0';
 
        if ((rv = rump_sys_ioctl(s, SIOCGIFFLAGS, &ifr)) < 0) {
                atf_tc_fail_errno("if config get flags");
diff -r 6622dad0bdb0 -r 1e3a510cf047 tests/net/if_vlan/siocXmulti.c
--- a/tests/net/if_vlan/siocXmulti.c    Sun Oct 13 07:44:51 2019 +0000
+++ b/tests/net/if_vlan/siocXmulti.c    Sun Oct 13 07:46:16 2019 +0000
@@ -56,7 +56,8 @@
        if (ifidx == 0)
                err(1, "if_nametoindex(%s)", argv[ARG_IFNAME]);
 
-       strncpy(ifr.ifr_name, argv[ARG_IFNAME], sizeof(ifr.ifr_name));
+       strncpy(ifr.ifr_name, argv[ARG_IFNAME], sizeof(ifr.ifr_name) - 1);
+       ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
 
        sin = (struct sockaddr_in *)&ifr.ifr_addr;
        sin->sin_family = AF_INET;



Home | Main Index | Thread Index | Old Index