Skip to content

Commit e754277

Browse files
anonrigtargos
authored andcommitted
url: fix array overrun in node:url::SetArgs()
PR-URL: #47001 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 4219c1e commit e754277

File tree

1 file changed

+17
-41
lines changed

1 file changed

+17
-41
lines changed

src/node_url.cc

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ using v8::Local;
2020
using v8::NewStringType;
2121
using v8::Object;
2222
using v8::String;
23-
using v8::Undefined;
2423
using v8::Value;
2524

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

49-
void SetArgs(Environment* env, Local<Value> argv[10], const ada::result& url) {
48+
void SetArgs(Environment* env,
49+
Local<Value> (*argv)[10],
50+
const ada::result& url) {
5051
Isolate* isolate = env->isolate();
51-
argv[0] = Utf8String(isolate, url->get_href());
52-
argv[1] = Utf8String(isolate, url->get_origin());
53-
argv[2] = Utf8String(isolate, url->get_protocol());
54-
argv[3] = Utf8String(isolate, url->get_hostname());
55-
argv[4] = Utf8String(isolate, url->get_pathname());
56-
argv[5] = Utf8String(isolate, url->get_search());
57-
argv[6] = Utf8String(isolate, url->get_username());
58-
argv[7] = Utf8String(isolate, url->get_password());
59-
argv[8] = Utf8String(isolate, url->get_port());
60-
argv[9] = Utf8String(isolate, url->get_hash());
52+
(*argv)[0] = Utf8String(isolate, url->get_href());
53+
(*argv)[1] = Utf8String(isolate, url->get_origin());
54+
(*argv)[2] = Utf8String(isolate, url->get_protocol());
55+
(*argv)[3] = Utf8String(isolate, url->get_hostname());
56+
(*argv)[4] = Utf8String(isolate, url->get_pathname());
57+
(*argv)[5] = Utf8String(isolate, url->get_search());
58+
(*argv)[6] = Utf8String(isolate, url->get_username());
59+
(*argv)[7] = Utf8String(isolate, url->get_password());
60+
(*argv)[8] = Utf8String(isolate, url->get_port());
61+
(*argv)[9] = Utf8String(isolate, url->get_hash());
6162
}
6263

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

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

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

92-
const Local<Value> undef = Undefined(isolate);
93-
Local<Value> argv[] = {
94-
undef,
95-
undef,
96-
undef,
97-
undef,
98-
undef,
99-
undef,
100-
undef,
101-
undef,
102-
undef,
103-
undef,
104-
};
105-
SetArgs(env, argv, out);
92+
Local<Value> argv[10];
93+
SetArgs(env, &argv, out);
10694
USE(success_callback_->Call(
10795
env->context(), args.This(), arraysize(argv), argv));
10896
args.GetReturnValue().Set(true);
@@ -235,20 +223,8 @@ void UpdateUrl(const FunctionCallbackInfo<Value>& args) {
235223
}
236224
}
237225

238-
const Local<Value> undef = Undefined(isolate);
239-
Local<Value> argv[] = {
240-
undef,
241-
undef,
242-
undef,
243-
undef,
244-
undef,
245-
undef,
246-
undef,
247-
undef,
248-
undef,
249-
undef,
250-
};
251-
SetArgs(env, argv, out);
226+
Local<Value> argv[10];
227+
SetArgs(env, &argv, out);
252228
USE(success_callback_->Call(
253229
env->context(), args.This(), arraysize(argv), argv));
254230
args.GetReturnValue().Set(result);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy