mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 16:04:49 +00:00
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 <philippe.guibert@6wind.com>
This commit is contained in:
parent
c215ecaf83
commit
0362b0a7ec
@ -1125,13 +1125,15 @@ char *mac2str(char *mac, char *buf, int size)
|
|||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
assert (size > ETHER_ADDR_STRLEN);
|
|
||||||
if (!mac)
|
if (!mac)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!buf)
|
if (!buf)
|
||||||
ptr = (char *)XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN* sizeof(char));
|
ptr = (char *)XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN* sizeof(char));
|
||||||
else
|
else
|
||||||
ptr = buf;
|
{
|
||||||
|
assert (size >= ETHER_ADDR_STRLEN);
|
||||||
|
ptr = buf;
|
||||||
|
}
|
||||||
snprintf(ptr, (ETHER_ADDR_STRLEN),
|
snprintf(ptr, (ETHER_ADDR_STRLEN),
|
||||||
"%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t) mac[0],
|
"%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t) mac[0],
|
||||||
(uint8_t) mac[1], (uint8_t) mac[2], (uint8_t) mac[3],
|
(uint8_t) mac[1], (uint8_t) mac[2], (uint8_t) mac[3],
|
||||||
|
Loading…
Reference in New Issue
Block a user