From 7e02124a06264c73e2d20adff8d57ddba66c86a4 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 3 Oct 2021 10:25:19 +0530 Subject: [PATCH] dgram: add `nread` assertion to `UDPWrap::OnRecv` This asserts that the number of bytes received by the socket is less than or equal to the size allocated for the temporary storage. Signed-off-by: Darshan Sen PR-URL: https://github.com/nodejs/node/pull/40295 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Minwoo Jung --- src/udp_wrap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index f068995e9b068f..4a0c6aeaa940d2 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -20,7 +20,6 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. #include "udp_wrap.h" -#include "allocated_buffer-inl.h" #include "env-inl.h" #include "node_buffer.h" #include "node_sockaddr-inl.h" @@ -725,6 +724,7 @@ void UDPWrap::OnRecv(ssize_t nread, } else if (nread == 0) { bs = ArrayBuffer::NewBackingStore(isolate, 0); } else { + CHECK_LE(static_cast(nread), bs->ByteLength()); bs = BackingStore::Reallocate(isolate, std::move(bs), nread); }