Skip to content

Commit aa953a4

Browse files
committed
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
1 parent 4318b23 commit aa953a4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/tcp_wrap.cc

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,19 @@ 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+
return scope.Escape(info);
375+
}
373376
}
374377
port = ntohs(a6->sin6_port);
375378
info->Set(env->context(),

0 commit comments

Comments
 (0)