From: Philippe Guibert Date: Wed, 1 Feb 2017 18:05:19 +0000 (+0100) Subject: lib: handle str2mac case where buffer is allocated by the function X-Git-Tag: frr-3.0-branchpoint~29^2~20 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=0362b0a7ec8bdd58cea755d97972c2f2ae4a9bbf;p=mirror%2Ffrr.git lib: handle str2mac case where buffer is allocated by the function 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 --- diff --git a/lib/prefix.c b/lib/prefix.c index 75879b5c51..bef28ff9ec 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1125,13 +1125,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],