Skip to content

Commit

Permalink
src: don't print interface if sin6_scope_id is 0
Browse files Browse the repository at this point in the history
An interface with index 0 doesn't make sense and makes
`if_indextoname()` to return `ENXIO` which crashes the process.

Fixes: #41500

PR-URL: #41547
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
santigimeno authored and danielleadams committed Apr 24, 2022
1 parent 428b967 commit 86b9d3a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,20 @@ Local<Object> AddressToJS(Environment* env,
a6 = reinterpret_cast<const sockaddr_in6*>(addr);
uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip);
// Add an interface identifier to a link local address.
if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr)) {
const size_t addrlen = strlen(ip);
CHECK_LT(addrlen, sizeof(ip));
ip[addrlen] = '%';
size_t scopeidlen = sizeof(ip) - addrlen - 1;
CHECK_GE(scopeidlen, UV_IF_NAMESIZE);
const int r = uv_if_indextoiid(a6->sin6_scope_id,
ip + addrlen + 1,
&scopeidlen);
CHECK_EQ(r, 0);
if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr) && a6->sin6_scope_id > 0) {
const size_t addrlen = strlen(ip);
CHECK_LT(addrlen, sizeof(ip));
ip[addrlen] = '%';
size_t scopeidlen = sizeof(ip) - addrlen - 1;
CHECK_GE(scopeidlen, UV_IF_NAMESIZE);
const int r = uv_if_indextoiid(a6->sin6_scope_id,
ip + addrlen + 1,
&scopeidlen);
if (r) {
env->ThrowUVException(r, "uv_if_indextoiid");
// TODO(addaleax): Do proper MaybeLocal handling here
return scope.Escape(info);
}
}
port = ntohs(a6->sin6_port);
info->Set(env->context(),
Expand Down

0 comments on commit 86b9d3a

Please sign in to comment.