From 34769a15e305e878ac2087a9af8dad14ce3775ca Mon Sep 17 00:00:00 2001 From: 0xArdi-N <0x4rd1@gmail.com> Date: Mon, 6 Jan 2025 16:04:30 +0700 Subject: [PATCH] src: add args validation method --- src/tcp_wrap.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index d80de135c26b1e..bed6ffbfd56d7f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -291,6 +291,13 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { void TCPWrap::Connect(const FunctionCallbackInfo& args) { + if (args.Length() <= 2) { + // Throw an exception for insufficient arguments + args.GetIsolate()->ThrowException(v8::Exception::TypeError( + v8::String::NewFromUtf8(args.GetIsolate(), "Insufficient arguments").ToLocalChecked())); + return; + } + CHECK(args[2]->IsUint32()); // explicit cast to fit to libuv's type expectation int port = static_cast(args[2].As()->Value());