chiark / gitweb /
nspawn: fix truncation of machine names in interface names
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Aug 2014 05:28:21 +0000 (01:28 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Aug 2014 05:29:51 +0000 (01:29 -0400)
Based on patch by Michael Marineau <michael.marineau@coreos.com>:

When deriving the network interface name from machine name strncpy was
not properly null terminating the string and the maximum string size as
returned by strlen() is actually IFNAMSIZ-1, not IFNAMSIZ.

src/nspawn/nspawn.c

index ddf1c371a0f7459182e56ef2b046dabfd037ef97..b118c739e8c6b0f562b2daf14520d15443d420e4 100644 (file)
@@ -1659,11 +1659,8 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) {
 
         /* Use two different interface name prefixes depending whether
          * we are in bridge mode or not. */
-        if (arg_network_bridge)
-                memcpy(iface_name, "vb-", 3);
-        else
-                memcpy(iface_name, "ve-", 3);
-        strncpy(iface_name+3, arg_machine, IFNAMSIZ - 3);
+        snprintf(iface_name, IFNAMSIZ, "%s-%s",
+                 arg_network_bridge ? "vb" : "ve", arg_machine);
 
         r = get_mac(&mac);
         if (r < 0) {