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

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Aug 2 22:31:06 PDT 2014


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


More information about the systemd-devel mailing list