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 <darshan.sen@postman.com>

PR-URL: https://github.com/nodejs/node/pull/40295
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Darshan Sen authored and Michaël Zasso committed 2021-10-13 10:20:50 +02:00
1 parent 38d81380ac
commit 7e02124a06
1 file changed
+1 -1
+1 -1
View File
@@ -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<size_t>(nread), bs->ByteLength());
bs = BackingStore::Reallocate(isolate, std::move(bs), nread);
}