]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: don't corrupt memory for long hostnames
authorChristian Franke <chris@opensourcerouting.org>
Thu, 12 Nov 2015 13:09:08 +0000 (14:09 +0100)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 30 Mar 2016 00:26:15 +0000 (20:26 -0400)
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
isisd/isis_lsp.c
isisd/isis_tlv.h

index 82554d13ce1a80ed5ec0ac3fb4cb06e049e74c5b..2482b126c8e9dada9d00e90f2f99bd09f8f7a692 100644 (file)
@@ -1222,12 +1222,19 @@ lsp_build (struct isis_lsp *lsp, struct isis_area *area)
   /* Dynamic Hostname */
   if (area->dynhostname)
     {
+      const char *hostname = unix_hostname();
+      size_t hostname_len = strlen(hostname);
+
       lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
                                        sizeof (struct hostname));
 
-      memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
-             strlen (unix_hostname ()));
-      lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
+      strncpy((char *)lsp->tlv_data.hostname->name, hostname,
+              sizeof(lsp->tlv_data.hostname->name));
+      if (hostname_len <= MAX_TLV_LEN)
+        lsp->tlv_data.hostname->namelen = hostname_len;
+      else
+        lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
+
       tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
     }
 
index e092f4d6d2d7123adfc23119d3fa30edf432b626..f5b59a7963cf32f035be110734faa8354a4328e8 100644 (file)
 
 #define AUTH_INFO_HDRLEN          3
 
+#define MAX_TLV_LEN 255
+
 #define IS_NEIGHBOURS_LEN (ISIS_SYS_ID_LEN + 5)
 #define LAN_NEIGHBOURS_LEN 6
 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN) /* FIXME: should be entry */