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

Socket.connect results in an abort #56367

Open
zyscoder opened this issue Dec 26, 2024 · 1 comment
Open

Socket.connect results in an abort #56367

zyscoder opened this issue Dec 26, 2024 · 1 comment
Labels
net Issues and PRs related to the net subsystem.

Comments

@zyscoder
Copy link

Version

v22.11.0

Platform

Linux u24vm 6.8.0-50-generic #51-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov  9 17:58:29 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

net

What steps will reproduce the bug?

Setup a node instance,

» node

and run the following javascript code.

net = require('net');
s = new net.Socket(()=>{});
s.connect({port:250,localAddress:'string'});
s.connect('string', ()=>{});

Then the node instance occurs an abort.

How often does it reproduce? Is there a required condition?

This abort can always be triggered following the steps above.

What is the expected behavior? Why is that the expected behavior?

If any error occurs, an exception or similar error-reporting stuff should be thrown, caught, and handled correctly. There is no reason to abort the whole node process.

What do you see instead?

» node                                                                                               
Welcome to Node.js v22.11.0.
Type ".help" for more information.
> net = require('net');
{
  _createServerHandle: [Function: createServerHandle],
  _normalizeArgs: [Function: normalizeArgs],
  _setSimultaneousAccepts: [Function: _setSimultaneousAccepts],
  BlockList: [Getter],
  SocketAddress: [Getter],
  connect: [Function: connect],
  createConnection: [Function: connect],
  createServer: [Function: createServer],
  isIP: [Function: isIP],
  isIPv4: [Function: isIPv4],
  isIPv6: [Function: isIPv6],
  Server: [Function: Server],
  Socket: [Function: Socket],
  Stream: [Function: Socket],
  getDefaultAutoSelectFamily: [Function: getDefaultAutoSelectFamily],
  setDefaultAutoSelectFamily: [Function: setDefaultAutoSelectFamily],
  getDefaultAutoSelectFamilyAttemptTimeout: [Function: getDefaultAutoSelectFamilyAttemptTimeout],
  setDefaultAutoSelectFamilyAttemptTimeout: [Function: setDefaultAutoSelectFamilyAttemptTimeout]
}
> s = new net.Socket(()=>{});
Socket {
  connecting: false,
  _hadError: false,
  _parent: null,
  _host: null,
  _closeAfterHandlingError: false,
  _events: {
    close: undefined,
    error: undefined,
    prefinish: undefined,
    finish: undefined,
    drain: undefined,
    data: undefined,
    end: [Function: onReadableStreamEnd],
    readable: undefined
  },
  _readableState: ReadableState {
    highWaterMark: 65536,
    buffer: [],
    bufferIndex: 0,
    length: 0,
    pipes: [],
    awaitDrainWriters: null,
    [Symbol(kState)]: 1052932
  },
  _writableState: WritableState {
    highWaterMark: 65536,
    length: 0,
    corked: 0,
    onwrite: [Function: bound onwrite],
    writelen: 0,
    bufferedIndex: 0,
    pendingcb: 0,
    [Symbol(kState)]: 17564420,
    [Symbol(kBufferedValue)]: null
  },
  allowHalfOpen: false,
  _maxListeners: undefined,
  _eventsCount: 1,
  _sockname: null,
  _pendingData: null,
  _pendingEncoding: '',
  server: null,
  _server: null,
  [Symbol(async_id_symbol)]: -1,
  [Symbol(kHandle)]: null,
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(shapeMode)]: true,
  [Symbol(kCapture)]: false,
  [Symbol(kSetNoDelay)]: false,
  [Symbol(kSetKeepAlive)]: false,
  [Symbol(kSetKeepAliveInitialDelay)]: 0,
  [Symbol(kBytesRead)]: 0,
  [Symbol(kBytesWritten)]: 0
}
> s.connect({port:250,localAddress:'string'});
Uncaught TypeError [ERR_INVALID_IP_ADDRESS]: Invalid IP address: string
    at lookupAndConnect (node:net:1289:11)
    at Socket.connect (node:net:1258:5) {
  code: 'ERR_INVALID_IP_ADDRESS'
}
> s.connect('string', ()=>{});

  #  node[2385420]: static void node::TCPWrap::Connect(const v8::FunctionCallbackInfo<v8::Value>&) at ../src/tcp_wrap.cc:290
  #  Assertion failed: args[2]->IsUint32()

----- Native stack trace -----

 1: 0xf76527 node::Assert(node::AssertionInfo const&) [node]
 2: 0x10d2fb3 node::TCPWrap::Connect(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 3: 0x7e29d7c0f5e2

----- JavaScript stack trace -----

1: internalConnect (node:net:1086:24)
2: defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
3: Socket.connect (node:net:1254:5)
4: REPL4:1:3
5: runInThisContext (node:vm:137:12)
6: defaultEval (node:repl:598:22)
7: bound (node:domain:433:15)
8: runBound (node:domain:444:12)
9: onLine (node:repl:927:10)
10: emit (node:events:530:35)


[1]    2385420 IOT instruction (core dumped)  node

Additional information

No response

@marco-ippolito marco-ippolito added the net Issues and PRs related to the net subsystem. label Dec 26, 2024
@lpinca lpinca added repl Issues and PRs related to the REPL subsystem. and removed repl Issues and PRs related to the REPL subsystem. labels Dec 27, 2024
@ardinugrxha
Copy link
Contributor

at tcp_wrap.cc :290

I think there are not valid arguments before we init the connection to the socket. There are less than args[2] given from the parameter that caused the segmentation fault. Should we add some validation here (?)

void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
  CHECK(args[2]->IsUint32());
  // explicit cast to fit to libuv's type expectation
  int port = static_cast<int>(args[2].As<Uint32>()->Value());
  Connect<sockaddr_in>(args, [port](const char* ip_address, sockaddr_in* addr) {
    return uv_ip4_addr(ip_address, port, addr);
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants