This fixes #218 where we get a zero hardware address length in
an ARP packet or a length that overflows the string buffer.
const unsigned char *hp, *ep;
char *p;
- if (buf == NULL || hwlen == 0)
+ /* Allow a hwlen of 0 to be an empty string. */
+ if (buf == NULL || buflen == 0) {
+ errno = ENOBUFS;
return NULL;
+ }
if (hwlen * 3 > buflen) {
+ /* We should still terminate the string just in case. */
+ buf[0] = '\0';
errno = ENOBUFS;
return NULL;
}
hp = hwaddr;
ep = hp + hwlen;
p = buf;
-
while (hp < ep) {
if (hp != hwaddr)
*p ++= ':';