summary refs log tree commit diff
path: root/host
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-02-21 14:51:28 +0000
committerAlyssa Ross <hi@alyssa.is>2022-02-21 14:53:26 +0000
commitcbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b (patch)
treeaafb94f696a50196c7cc1ce3dcb10a5150fe8ade /host
parent338f3ad690e1061fe4e11f08815fa3d2519f51a6 (diff)
downloadspectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.tar
spectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.tar.gz
spectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.tar.bz2
spectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.tar.lz
spectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.tar.xz
spectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.tar.zst
spectrum-cbc3e29a0f5a7d0cdcc535d6530dc3b9c8c2b85b.zip
host/start-vm: tap_open: check length before copy
This way of doing it stops GCC's stringop-truncation warning in this
case.  (But it still fires spuriously in other cases so we're keeping
it disabled.)
Diffstat (limited to 'host')
-rw-r--r--host/start-vm/net-util.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/host/start-vm/net-util.c b/host/start-vm/net-util.c
index dc5032c..33845b8 100644
--- a/host/start-vm/net-util.c
+++ b/host/start-vm/net-util.c
@@ -143,14 +143,14 @@ int tap_open(char name[static IFNAMSIZ], int flags)
 	struct ifreq ifr;
 	int fd;
 
-	strncpy(ifr.ifr_name, name, IFNAMSIZ);
-	ifr.ifr_flags = IFF_TAP|flags;
-
-	if (ifr.ifr_name[IFNAMSIZ - 1]) {
+	if (name[IFNAMSIZ - 1]) {
 		errno = ENAMETOOLONG;
 		return -1;
 	}
 
+	strncpy(ifr.ifr_name, name, IFNAMSIZ - 1);
+	ifr.ifr_flags = IFF_TAP|flags;
+
 	if ((fd = open("/dev/net/tun", O_RDWR)) == -1)
 		return -1;
 	if (ioctl(fd, TUNSETIFF, &ifr) == -1) {