ifr_name is nul terminated. make it so.

This commit is contained in:
mrg 2019-10-13 07:46:16 +00:00
parent 4efb79b1f1
commit 4e545ef793
2 changed files with 8 additions and 5 deletions

View File

@ -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 @@ 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");

View File

@ -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;