Re: [systemd-devel] [PATCH] nspawn: fix truncation of machine names in interface names

2014-08-02 Thread Zbigniew Jędrzejewski-Szmek
On Tue, Jul 29, 2014 at 03:18:58PM -0700, Michael Marineau wrote:
 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);
I pushed a different patch, which simply uses snprintf, as that seems
a less error-prone solution. I stole your commit message though :)

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] nspawn: fix truncation of machine names in interface names

2014-07-29 Thread Michael Marineau
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

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel