From b4c8fd8c55278e935b772235251837205aa3ba66 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 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 440f51c1220d73d..a771b14dd475d17 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -276,14 +276,9 @@ void TCPWrap::Listen(const FunctionCallbackInfo& args) { } void TCPWrap::Connect(const FunctionCallbackInfo& args) { - if (args.Length() <= 2) { - args.GetIsolate()->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(args.GetIsolate(), "Insufficient arguments") - .ToLocalChecked())); - return; - } - - CHECK(args[2]->IsUint32()); + Environment* env = Environment::GetCurrent(args); + int backlog; + if (!args[2]->Int32Value(env->context()).To(&backlog)) return; // explicit cast to fit to libuv's type expectation int port = static_cast(args[2].As()->Value()); Connect(args, [port](const char* ip_address, sockaddr_in* addr) { @@ -293,7 +288,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args) { void TCPWrap::Connect6(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - CHECK(args[2]->IsUint32()); + int port; if (!args[2]->Int32Value(env->context()).To(&port)) return; Connect(args,