Skip to content

Commit

Permalink
src: fix crash on OnStreamRead on Windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
santigimeno committed Dec 15, 2022
1 parent 4166d40 commit b7c2cd2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/stream_base.cc
Expand Up @@ -583,9 +583,10 @@ void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

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

0 comments on commit b7c2cd2

Please sign in to comment.