Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node::Abort() in udpSocket.send(msg, port, address) if UDP socket is connected #28126

Closed
ibc opened this issue Jun 7, 2019 · 1 comment
Closed

Comments

@ibc
Copy link

ibc commented Jun 7, 2019

  • Version: v12.4.0
  • Platform: Darwin macbook 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • Subsystem: dgram
const dgram = require('dgram');

const udpSocket = dgram.createSocket({ type: 'udp4' });

udpSocket.connect(1234, '127.0.0.1', (error) =>
{
  console.log('UDP socket connected (error:%s)', String(error));

  // This is the proper way to send data on a connected UDP socket.
  // udpSocket.send('foo', (error) => console.log('error:', error));

  // This is for non connected UDP sockets. Anyway it should NOT produce an abort.
  udpSocket.send('foo', 1234, '127.0.0.1', (error) => console.log('error:', error));
});

It produces:

UDP socket connected (error:undefined)
node[78453]: ../src/udp_wrap.cc:417:static void node::UDPWrap::DoSend(const FunctionCallbackInfo<v8::Value> &, int): Assertion `args[3]->IsUint32()' failed.
 1: 0x100075bd5 node::Abort() [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
 2: 0x10007597d node::AppendExceptionLine(node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Message>, node::ErrorHandlingMode) [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
 3: 0x1001036f5 node::UDPWrap::DoSend(v8::FunctionCallbackInfo<v8::Value> const&, int) [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
 4: 0x1001f0c84 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
 5: 0x1001f0294 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
 6: 0x1001ef840 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
 7: 0x100ea9f02 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/ibc/.nvm/versions/node/v12.4.0/bin/node]
Abort trap: 6

To clarify, the code above creates a UDP socket, connects it, and then uses the send() API by including the remote port and address (which are useless or even invalid in a connected UDP socket).

Not sure if send() should throw due the useless/invalid presence of port and address arguments, but it should not crash.

@ibc
Copy link
Author

ibc commented Jun 8, 2019

Note that, according to the libuv UDP handle:

For connected UDP handles, addr must be set to NULL, otherwise it will return UV_EISCONN error.

For connectionless UDP handles, addr cannot be NULL, otherwise it will return UV_EDESTADDRREQ error.

However, the issue here is a CHECK(args[2]->IsUint32()) in udp_wrap.cc that causes the above abort.

BridgeAR pushed a commit that referenced this issue Jun 17, 2019
This commit fixes a C++ abort for connected dgram sockets
by improving input validation in the JS layer.

Fixes: #28126
PR-URL: #28135
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant