From 4e545ef793ffd691532a71002a95c1054044ae1e Mon Sep 17 00:00:00 2001 From: mrg Date: Sun, 13 Oct 2019 07:46:16 +0000 Subject: [PATCH] ifr_name is nul terminated. make it so. --- tests/net/can/h_canutils.c | 10 ++++++---- tests/net/if_vlan/siocXmulti.c | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/net/can/h_canutils.c b/tests/net/can/h_canutils.c index 7f2ba9802203..050a579b2bc6 100644 --- a/tests/net/can/h_canutils.c +++ b/tests/net/can/h_canutils.c @@ -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 #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 @@ -70,14 +70,16 @@ cancfg_rump_createif(const char *ifname) } 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 --git a/tests/net/if_vlan/siocXmulti.c b/tests/net/if_vlan/siocXmulti.c index a256b245aa7e..ddb8ecb72ed9 100644 --- a/tests/net/if_vlan/siocXmulti.c +++ b/tests/net/if_vlan/siocXmulti.c @@ -56,7 +56,8 @@ main(int argc, char *argv[]) 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;