Skip to content

net: validate non-string host for socket.connect#57198

Merged
nodejs-github-bot merged 1 commit intonodejs:mainfrom
daeyeon:main.net-connect-250224.Mon.9882
Mar 11, 2025
Merged

net: validate non-string host for socket.connect#57198
nodejs-github-bot merged 1 commit intonodejs:mainfrom
daeyeon:main.net-connect-250224.Mon.9882

Conversation

@daeyeon
Copy link
Member

@daeyeon daeyeon commented Feb 24, 2025

This fixes another issue discovered while reviewing #57112.

Internally, socket.connect checks the host string, implicitly coercing an array to a string in the process. That leads to the error below.

import net from 'node:net';

net.createConnection({
  host: ['192.168.0.1'],
  port: 8080,
});
#  node[2568546]: static void node::TCPWrap::Connect(const v8::FunctionCallbackInfo<v8::Value>&, std::function<int(const char*, T*)>) [with T = sockaddr_in] at ../src/tcp_wrap.cc:325
#  Assertion failed: args[1]->IsString()

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

 1: 0x102d7b7 node::Assert(node::AssertionInfo const&) [node]
 2: 0x11aa8c2 void node::TCPWrap::Connect<sockaddr_in>(v8::FunctionCallbackInfo<v8::Value> const&, std::function<int (char const*, sockaddr_in*)>) [node]
 3: 0x11a9a73 node::TCPWrap::Connect(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 4: 0x7f5b17e0f186

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

1: internalConnect (node:net:1096:26)
2: defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
3: node:net:1353:9
4: processTicksAndRejections (node:internal/process/task_queues:85:11)

Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants