Skip to content

Commit

Permalink
url: fix array overrun in node:url::SetArgs()
Browse files Browse the repository at this point in the history
PR-URL: nodejs#47001
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
anonrig authored Mar 10, 2023
1 parent 1ccc8cc commit 72e971e
Showing 1 changed file with 17 additions and 41 deletions.
58 changes: 17 additions & 41 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Undefined;
using v8::Value;

Local<String> Utf8String(Isolate* isolate, const std::string& str) {
Expand All @@ -46,18 +45,20 @@ enum url_update_action {
kHref = 9,
};

void SetArgs(Environment* env, Local<Value> argv[10], const ada::result& url) {
void SetArgs(Environment* env,
Local<Value> (*argv)[10],
const ada::result& url) {
Isolate* isolate = env->isolate();
argv[0] = Utf8String(isolate, url->get_href());
argv[1] = Utf8String(isolate, url->get_origin());
argv[2] = Utf8String(isolate, url->get_protocol());
argv[3] = Utf8String(isolate, url->get_hostname());
argv[4] = Utf8String(isolate, url->get_pathname());
argv[5] = Utf8String(isolate, url->get_search());
argv[6] = Utf8String(isolate, url->get_username());
argv[7] = Utf8String(isolate, url->get_password());
argv[8] = Utf8String(isolate, url->get_port());
argv[9] = Utf8String(isolate, url->get_hash());
(*argv)[0] = Utf8String(isolate, url->get_href());
(*argv)[1] = Utf8String(isolate, url->get_origin());
(*argv)[2] = Utf8String(isolate, url->get_protocol());
(*argv)[3] = Utf8String(isolate, url->get_hostname());
(*argv)[4] = Utf8String(isolate, url->get_pathname());
(*argv)[5] = Utf8String(isolate, url->get_search());
(*argv)[6] = Utf8String(isolate, url->get_username());
(*argv)[7] = Utf8String(isolate, url->get_password());
(*argv)[8] = Utf8String(isolate, url->get_port());
(*argv)[9] = Utf8String(isolate, url->get_hash());
}

void Parse(const FunctionCallbackInfo<Value>& args) {
Expand All @@ -69,7 +70,6 @@ void Parse(const FunctionCallbackInfo<Value>& args) {
Local<Function> success_callback_ = args[2].As<Function>();

Environment* env = Environment::GetCurrent(args);
Isolate* isolate = env->isolate();
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand All @@ -89,20 +89,8 @@ void Parse(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().Set(false);
}

const Local<Value> undef = Undefined(isolate);
Local<Value> argv[] = {
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
};
SetArgs(env, argv, out);
Local<Value> argv[10];
SetArgs(env, &argv, out);
USE(success_callback_->Call(
env->context(), args.This(), arraysize(argv), argv));
args.GetReturnValue().Set(true);
Expand Down Expand Up @@ -235,20 +223,8 @@ void UpdateUrl(const FunctionCallbackInfo<Value>& args) {
}
}

const Local<Value> undef = Undefined(isolate);
Local<Value> argv[] = {
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
undef,
};
SetArgs(env, argv, out);
Local<Value> argv[10];
SetArgs(env, &argv, out);
USE(success_callback_->Call(
env->context(), args.This(), arraysize(argv), argv));
args.GetReturnValue().Set(result);
Expand Down

0 comments on commit 72e971e

Please sign in to comment.