diff options
author | Renato Botelho <renato@netgate.com> | 2016-12-14 13:59:40 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-12-14 13:59:40 -0200 |
commit | cc9fac304cafadab4656653aa1a62fdad74b4e94 (patch) | |
tree | 43fee446af0c829986548dcbe6862d3ac31bae2e /lib/libc | |
parent | 812767d2bb4e201b4f826fd31924d2cafb8fe0ae (diff) | |
parent | 6d3cdf0ab519f1b7bad6bd132eda48242f0ff7c8 (diff) | |
download | FreeBSD-src-cc9fac304cafadab4656653aa1a62fdad74b4e94.zip FreeBSD-src-cc9fac304cafadab4656653aa1a62fdad74b4e94.tar.gz |
Merge remote-tracking branch 'origin/stable/10' into devel
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/linkaddr.c | 52 | ||||
-rw-r--r-- | lib/libc/tests/stdio/printbasic_test.c | 4 |
2 files changed, 36 insertions, 20 deletions
diff --git a/lib/libc/net/linkaddr.c b/lib/libc/net/linkaddr.c index 5be6e74..fec220a 100644 --- a/lib/libc/net/linkaddr.c +++ b/lib/libc/net/linkaddr.c @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/socket.h> +#include <net/if.h> #include <net/if_dl.h> #include <string.h> @@ -125,31 +126,46 @@ link_ntoa(sdl) const struct sockaddr_dl *sdl; { static char obuf[64]; - char *out = obuf; - int i; - u_char *in = (u_char *)LLADDR(sdl); - u_char *inlim = in + sdl->sdl_alen; - int firsttime = 1; + _Static_assert(sizeof(obuf) >= IFNAMSIZ + 20, "obuf is too small"); + char *out; + const u_char *in, *inlim; + int namelen, i, rem; - if (sdl->sdl_nlen) { - bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); - out += sdl->sdl_nlen; - if (sdl->sdl_alen) + namelen = (sdl->sdl_nlen <= IFNAMSIZ) ? sdl->sdl_nlen : IFNAMSIZ; + + out = obuf; + rem = sizeof(obuf); + if (namelen > 0) { + bcopy(sdl->sdl_data, out, namelen); + out += namelen; + rem -= namelen; + if (sdl->sdl_alen > 0) { *out++ = ':'; + rem--; + } } - while (in < inlim) { - if (firsttime) - firsttime = 0; - else + + in = (const u_char *)sdl->sdl_data + sdl->sdl_nlen; + inlim = in + sdl->sdl_alen; + + while (in < inlim && rem > 1) { + if (in != (const u_char *)sdl->sdl_data + sdl->sdl_nlen) { *out++ = '.'; + rem--; + } i = *in++; if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else + if (rem < 3) + break; + *out++ = hexlist[i >> 4]; + *out++ = hexlist[i & 0xf]; + rem -= 2; + } else { + if (rem < 2) + break; *out++ = hexlist[i]; + rem--; + } } *out = 0; return (obuf); diff --git a/lib/libc/tests/stdio/printbasic_test.c b/lib/libc/tests/stdio/printbasic_test.c index bebb734..7f7c6cb 100644 --- a/lib/libc/tests/stdio/printbasic_test.c +++ b/lib/libc/tests/stdio/printbasic_test.c @@ -124,10 +124,10 @@ ATF_TC_BODY(int_within_limits, tc) testfmt(S_ULONGMAX, "%lu", ULONG_MAX); testfmt("-1", "%lld", (long long)-1); - testfmt(S_ULONGMAX, "%lu", ULLONG_MAX); + testfmt(S_ULLONGMAX, "%llu", ULLONG_MAX); testfmt("-1", "%d", -1); - testfmt(S_UINT32MAX, "%lu", UINT32_MAX); + testfmt(S_UINT32MAX, "%u", UINT32_MAX); testfmt("-1", "%hd", -1); testfmt("65535", "%hu", USHRT_MAX); |