Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantiago Gimeno <santiago.gimeno@gmail.com>2022-02-11 14:33:07 +0300
committerGitHub <noreply@github.com>2022-02-11 14:33:07 +0300
commit3b338cfbe9fd649ab9407b9be3661cbc8a081058 (patch)
treece62cd947c4283e7827e3b9c194d00e3e72c6bea /src/tcp_wrap.cc
parent69ffb3e77f3b75dec6ec18a1090e5349b78c03c6 (diff)
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: https://github.com/nodejs/node/issues/41500 PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/tcp_wrap.cc')
-rw-r--r--src/tcp_wrap.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc
index 84b18a1592d..669206fc6bf 100644
--- a/src/tcp_wrap.cc
+++ b/src/tcp_wrap.cc
@@ -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(),