Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

stream_wrap: Fix issue with null file handles #25535

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());

StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
if ( NULL == wrap) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the space between ( and NULL in all of your if statements. I think core normally writes as wrap == NULL as well.

args.GetReturnValue().Set(UV_EBADF);
return;
}

assert(args[0]->IsObject());
assert(Buffer::HasInstance(args[1]));
Expand Down Expand Up @@ -283,6 +287,11 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {

StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());

if ( NULL == wrap) {
args.GetReturnValue().Set(UV_EBADF);
return;
}

assert(args[0]->IsObject());
assert(args[1]->IsString());

Expand Down Expand Up @@ -411,6 +420,14 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {

StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());

if ( NULL == wrap) {
// wrap is set to NULL when the handle for the request
// is closed. Since the handle is no longer valid return
// UV_EBADF to indicate this
args.GetReturnValue().Set(UV_EBADF);
return;
}

assert(args[0]->IsObject());
assert(args[1]->IsArray());

Expand Down Expand Up @@ -539,6 +556,10 @@ void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(env->isolate());

StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder());
if ( NULL == wrap) {
args.GetReturnValue().Set(UV_EBADF);
return;
}

assert(args.Length() > 0);
int err = uv_stream_set_blocking(wrap->stream(), args[0]->IsTrue());
Expand Down