Skip to content

Commit

Permalink
dgram: add nread assertion to UDPWrap::OnRecv
Browse files Browse the repository at this point in the history
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: #40295
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
RaisinTen authored and targos committed Oct 13, 2021
1 parent 38d8138 commit 7e02124
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/udp_wrap.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7e02124

Please sign in to comment.