diff mbox

ip/link_vti6.c: Fix local/remote any handling

Message ID 4608c5ed-6b73-4bc2-f193-66e5129d855e@secunet.com
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Christian Langrock Aug. 7, 2017, 6:41 a.m. UTC
According to the IPv4 behavior of 'ip' it should be possible to omit the
arguments for local and remote address.
Without this patch omitting these parameters would lead to
uninitialized memory being interpreted as IPv6 addresses.

Signed-off-by: Christian Langrock <christian.langrock@secunet.com>
---
 ip/link_vti6.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

     unsigned int link = 0;
@@ -167,6 +169,7 @@ get_failed:
 
                 get_prefix(&addr, *argv, AF_INET6);
                 memcpy(&daddr, addr.data, addr.bytelen);
+                use_daddr = true;
             }
         } else if (!matches(*argv, "local")) {
             NEXT_ARG();
@@ -178,6 +181,7 @@ get_failed:
 
                 get_prefix(&addr, *argv, AF_INET6);
                 memcpy(&saddr, addr.data, addr.bytelen);
+                use_saddr = true;
             }
         } else if (!matches(*argv, "dev")) {
             NEXT_ARG();
@@ -195,8 +199,10 @@ get_failed:
 
     addattr32(n, 1024, IFLA_VTI_IKEY, ikey);
     addattr32(n, 1024, IFLA_VTI_OKEY, okey);
-    addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, sizeof(saddr));
-    addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, sizeof(daddr));
+    if (use_saddr)
+        addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, sizeof(saddr));
+    if (use_daddr)
+        addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, sizeof(daddr));
     addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark);
     if (link)
         addattr32(n, 1024, IFLA_VTI_LINK, link);
diff mbox

Patch

diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index be4e33c..220b7df 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -60,7 +60,9 @@  static int vti6_parse_opt(struct link_util *lu, int
argc, char **argv,
     struct rtattr *linkinfo[IFLA_INFO_MAX+1];
     struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
     struct in6_addr saddr;
+    bool use_saddr = false;
     struct in6_addr daddr;
+    bool use_daddr = false;
     unsigned int ikey = 0;
     unsigned int okey = 0;