summary refs log tree commit diff
path: root/host
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-02-21 14:15:20 +0000
committerAlyssa Ross <hi@alyssa.is>2022-02-21 14:42:25 +0000
commit8e2a5a2957ef4191c6d8e203b33bd3e9029d260a (patch)
treedc07baf173c27f7615050002b0eff71b64466470 /host
parent2adcaf59ea3902f0116f1703dfbfe084623edcba (diff)
downloadspectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.tar
spectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.tar.gz
spectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.tar.bz2
spectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.tar.lz
spectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.tar.xz
spectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.tar.zst
spectrum-8e2a5a2957ef4191c6d8e203b33bd3e9029d260a.zip
host/start-vm: bridge_add: don't accept % in names
Linux will accept %d and dynamically fill it in, but it doesn't update
the string it was given, so there's no way to know what name was
chosen with this API.  If we wanted to support this, we'd probably
have to use the netlink API instead.  Right now, we don't need the
kernel to allocate bridge names for us, so let's just reject the names
we can't handle instead.

We only need to check for the presence of a % character, rather than
doing anything more complicated, because network interfaces aren't
actually allowed to have % in their names, so any % character is
either part of a %d that gets replaced, or will be rejected by the
kernel.
Diffstat (limited to 'host')
-rw-r--r--host/start-vm/net-util.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/host/start-vm/net-util.c b/host/start-vm/net-util.c
index f4c454f..7e112c1 100644
--- a/host/start-vm/net-util.c
+++ b/host/start-vm/net-util.c
@@ -71,6 +71,12 @@ out:
 int bridge_add(const char *name)
 {
 	int fd, r;
+
+	if (strchr(name, '%')) {
+		errno = EINVAL;
+		return -1;
+	}
+
 	if ((fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0)) == -1)
 		return -1;
 	r = ioctl(fd, SIOCBRADDBR, name);