Skip to content

Commit 6076291

Browse files
santigimenobengl
authored andcommitted
src: don't print interface if sin6_scope_id is 0
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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent b968d89 commit 6076291

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/tcp_wrap.cc

+14-10
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,20 @@ Local<Object> AddressToJS(Environment* env,
360360
a6 = reinterpret_cast<const sockaddr_in6*>(addr);
361361
uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip);
362362
// Add an interface identifier to a link local address.
363-
if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr)) {
364-
const size_t addrlen = strlen(ip);
365-
CHECK_LT(addrlen, sizeof(ip));
366-
ip[addrlen] = '%';
367-
size_t scopeidlen = sizeof(ip) - addrlen - 1;
368-
CHECK_GE(scopeidlen, UV_IF_NAMESIZE);
369-
const int r = uv_if_indextoiid(a6->sin6_scope_id,
370-
ip + addrlen + 1,
371-
&scopeidlen);
372-
CHECK_EQ(r, 0);
363+
if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr) && a6->sin6_scope_id > 0) {
364+
const size_t addrlen = strlen(ip);
365+
CHECK_LT(addrlen, sizeof(ip));
366+
ip[addrlen] = '%';
367+
size_t scopeidlen = sizeof(ip) - addrlen - 1;
368+
CHECK_GE(scopeidlen, UV_IF_NAMESIZE);
369+
const int r = uv_if_indextoiid(a6->sin6_scope_id,
370+
ip + addrlen + 1,
371+
&scopeidlen);
372+
if (r) {
373+
env->ThrowUVException(r, "uv_if_indextoiid");
374+
// TODO(addaleax): Do proper MaybeLocal handling here
375+
return scope.Escape(info);
376+
}
373377
}
374378
port = ntohs(a6->sin6_port);
375379
info->Set(env->context(),

0 commit comments

Comments
 (0)