Skip to content

Commit b7c2cd2

Browse files
committed
src: fix crash on OnStreamRead on Windows
On Windows it's perfectly possible that the `uv_tcp_t` `read_cb` is called with an error and a null `uv_buf_t` if it corresponds to a `UV_HANDLE_ZERO_READ` read. Handle this case without crashing. Fixes: #40764
1 parent 4166d40 commit b7c2cd2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/stream_base.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,10 @@ void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
583583
HandleScope handle_scope(env->isolate());
584584
Context::Scope context_scope(env->context());
585585

586-
// To deal with the case where POLLHUP is received and UV_EOF is returned, as
587-
// libuv returns an empty buffer (on unices only).
588-
if (nread == UV_EOF && buf.base == nullptr) {
586+
// In the case that there's an error and buf in null, return immediately.
587+
// This can happen on unices when POLLHUP is received and UV_EOF is returned
588+
// or when getting an error while performing a UV_HANDLE_ZERO_READ on Windows.
589+
if (buf.base == nullptr && nread < 0) {
589590
stream->CallJSOnreadMethod(nread, Local<ArrayBuffer>());
590591
return;
591592
}

0 commit comments

Comments
 (0)