]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: handle str2mac case where buffer is allocated by the function
authorPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 1 Feb 2017 18:05:19 +0000 (19:05 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 1 Feb 2017 18:05:19 +0000 (19:05 +0100)
The case where no buffer is passed to the str2mac function is handled.
In that case, a buffer is allocated. Then the check against the buffer
length is not done.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
lib/prefix.c

index 7987542632cd61df95a00e46b59a1c0087f6273d..407b3e510a3cb5d1a42db83e6a1af5b1725e31a3 100644 (file)
@@ -1119,13 +1119,15 @@ char *mac2str(char *mac, char *buf, int size)
 {
   char *ptr;
   
-  assert (size > ETHER_ADDR_STRLEN);
   if (!mac)
     return NULL;
   if (!buf)
     ptr = (char *)XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN* sizeof(char));
   else
-    ptr = buf;
+    {
+      assert (size >= ETHER_ADDR_STRLEN);
+      ptr = buf;
+    }
   snprintf(ptr, (ETHER_ADDR_STRLEN),
            "%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t) mac[0],
            (uint8_t) mac[1], (uint8_t) mac[2], (uint8_t) mac[3],