summary refs log tree commit diff
path: root/host
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-02-20 12:37:55 +0000
committerAlyssa Ross <hi@alyssa.is>2022-02-20 12:40:44 +0000
commit3c461d5d189b2637e76223c21c7501aaf7085f0a (patch)
treef62f82533fc06ec5bbf78f122290d974cfe341f5 /host
parent0f81f151e66b32529e38d3a505d13d02103a015f (diff)
downloadspectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.tar
spectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.tar.gz
spectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.tar.bz2
spectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.tar.lz
spectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.tar.xz
spectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.tar.zst
spectrum-3c461d5d189b2637e76223c21c7501aaf7085f0a.zip
host/start-vm: tap_open: check name length
Diffstat (limited to 'host')
-rw-r--r--host/start-vm/net-util.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/host/start-vm/net-util.c b/host/start-vm/net-util.c
index 1303762..cc6b950 100644
--- a/host/start-vm/net-util.c
+++ b/host/start-vm/net-util.c
@@ -2,6 +2,7 @@
 // SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
 
 #include <err.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <net/if.h>
 #include <string.h>
@@ -130,11 +131,16 @@ int tap_open(const char *name, int flags)
 	struct ifreq ifr;
 	int fd;
 
-	if ((fd = open("/dev/net/tun", O_RDWR)) == -1)
-		return -1;
-
 	strncpy(ifr.ifr_name, name, IFNAMSIZ);
 	ifr.ifr_flags = IFF_TAP|flags;
+
+	if (ifr.ifr_name[IFNAMSIZ - 1]) {
+		errno = ENAMETOOLONG;
+		return -1;
+	}
+
+	if ((fd = open("/dev/net/tun", O_RDWR)) == -1)
+		return -1;
 	if (!ioctl(fd, TUNSETIFF, &ifr))
 		return fd;