Skip to content

Commit

Permalink
udp: use libuv API to get file descriptor
Browse files Browse the repository at this point in the history
Refs: #6838
PR-URL: #6908
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
saghul committed May 23, 2016
1 parent ef9778c commit 3ef2eb2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {


void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
int fd = -1;
#if !defined(_WIN32)
HandleScope scope(args.GetIsolate());
UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());
int fd = (wrap == nullptr) ? -1 : wrap->handle_.io_watcher.fd;
args.GetReturnValue().Set(fd);
if (wrap != nullptr)
uv_fileno(reinterpret_cast<uv_handle_t*>(&wrap->handle_), &fd);
#endif
args.GetReturnValue().Set(fd);
}


Expand Down

4 comments on commit 3ef2eb2

@trevnorris
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for future note, this change will not prevent the application from aborting if the internal pointer hasn't yet been set b/c by default it's filled with garbage and not manually null-ed out. I have a fix for this in #6184.

@saghul
Copy link
Member Author

@saghul saghul commented on 3ef2eb2 May 24, 2016

Choose a reason for hiding this comment

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

@trevnorris you mean wrap->handle_ contains garbage? In that case no, this doesn't take care of that.

@trevnorris
Copy link
Contributor

Choose a reason for hiding this comment

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

@saghul I mean that wrap != nullptr will return true even if Wrap() hasn't run on the class yet, because the v8::Object's internal slot will contain garbage. Thus accessing wrap->handle_ will cause the process to abort because the returned pointer is invalid.

@saghul
Copy link
Member Author

@saghul saghul commented on 3ef2eb2 May 24, 2016

Choose a reason for hiding this comment

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

Ouch. I wasn't aware of this.

Please sign in to comment.