[systemd-devel] [PATCH] nspawn: fix truncation of machine names in interface names
Michael Marineau
michael.marineau at coreos.com
Tue Jul 29 15:18:58 PDT 2014
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 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 7c47f6e..73eeed6 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -69,6 +69,7 @@
#include "missing.h"
#include "cgroup-util.h"
#include "strv.h"
+#include "strxcpyx.h"
#include "path-util.h"
#include "loopback-setup.h"
#include "dev-setup.h"
@@ -1663,7 +1664,7 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) {
memcpy(iface_name, "vb-", 3);
else
memcpy(iface_name, "ve-", 3);
- strncpy(iface_name+3, arg_machine, IFNAMSIZ - 3);
+ strscpy(iface_name+3, IFNAMSIZ - 4, arg_machine);
r = get_mac(&mac);
if (r < 0) {
--
1.8.5.5
More information about the systemd-devel
mailing list