From 8216691fd945cc73cfd97383351e1f8f7923ec20 Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Wed, 18 Mar 2020 08:46:40 +0100 Subject: [PATCH 1/2] src: check for empty maybe local Using ToLocalChecked on MaybeLocal without verifying it's empty can lead to unattempted crash. --- src/udp_wrap.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 277eb6b81bae32..e70490cd8cf2ff 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -516,7 +516,9 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { // construct uv_buf_t array for (size_t i = 0; i < count; i++) { - Local chunk = chunks->Get(env->context(), i).ToLocalChecked(); + MaybeLocal maybe_chunk = chunks->Get(env->context(), i); + if (maybe_chunk.IsEmpty()) return; + Local chunk = maybe_chunk.ToLocalChecked(); size_t length = Buffer::Length(chunk); From 3d429e0d7966d860a45f6f0f7cf027ec6fc88341 Mon Sep 17 00:00:00 2001 From: Xavier Stouder Date: Wed, 18 Mar 2020 10:04:05 +0100 Subject: [PATCH 2/2] chore: simplify code --- src/udp_wrap.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index e70490cd8cf2ff..770782ee9cf38e 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -516,9 +516,8 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { // construct uv_buf_t array for (size_t i = 0; i < count; i++) { - MaybeLocal maybe_chunk = chunks->Get(env->context(), i); - if (maybe_chunk.IsEmpty()) return; - Local chunk = maybe_chunk.ToLocalChecked(); + Local chunk; + if (!chunks->Get(env->context(), i).ToLocal(&chunk)) return; size_t length = Buffer::Length(chunk);