Skip to content

Commit ff5ab6f

Browse files
santigimenotargos
authored andcommittedApr 22, 2020
net: fix crash if POLLHUP is received
If the `onread` socket option is used and a `POLLHUP` event is received, libuv returns `UV_EOF` along with a `NULL` buffer in the read callback, causing the crash. Deal with this case. Fixes: #31823 PR-URL: #32590 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent fabb53e commit ff5ab6f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎src/stream_base.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,21 @@ uv_buf_t CustomBufferJSListener::OnStreamAlloc(size_t suggested_size) {
508508

509509
void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
510510
CHECK_NOT_NULL(stream_);
511-
CHECK_EQ(buf.base, buffer_.base);
512511

513512
StreamBase* stream = static_cast<StreamBase*>(stream_);
514513
Environment* env = stream->stream_env();
515514
HandleScope handle_scope(env->isolate());
516515
Context::Scope context_scope(env->context());
517516

517+
// To deal with the case where POLLHUP is received and UV_EOF is returned, as
518+
// libuv returns an empty buffer (on unices only).
519+
if (nread == UV_EOF && buf.base == nullptr) {
520+
stream->CallJSOnreadMethod(nread, Local<ArrayBuffer>());
521+
return;
522+
}
523+
524+
CHECK_EQ(buf.base, buffer_.base);
525+
518526
MaybeLocal<Value> ret = stream->CallJSOnreadMethod(nread,
519527
Local<ArrayBuffer>(),
520528
0,

0 commit comments

Comments
 (0)
Please sign in to comment.