Skip to content

Commit 80e0f14

Browse files
authored
url: process crash via malformed UNC hostname in pathToFileURL()
Fixes: #62546 PR-URL: #62574 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Claudio Wunder <cwunder@gnome.org>
1 parent 66054cc commit 80e0f14

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/node_url.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ constexpr auto lookup_table = []() consteval {
9393
case CHAR: \
9494
result[i] = {{'%', HEX_DIGIT_2, HEX_DIGIT_1, 0}}; \
9595
break;
96-
9796
ENCODE_CHAR('\0', '0', '0') // '\0' == 0x00
9897
ENCODE_CHAR('\t', '0', '9') // '\t' == 0x09
9998
ENCODE_CHAR('\n', '0', 'A') // '\n' == 0x0A
@@ -169,7 +168,11 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo<Value>& args) {
169168
[[unlikely]] {
170169
CHECK(args[2]->IsString());
171170
Utf8Value hostname(isolate, args[2]);
172-
CHECK(out->set_hostname(hostname.ToStringView()));
171+
if (!out->set_hostname(hostname.ToStringView())) {
172+
return ThrowInvalidURL(realm->env(),
173+
input.ToStringView(),
174+
std::string(hostname.ToStringView()));
175+
}
173176
}
174177

175178
binding_data->UpdateComponents(out->get_components(), out->type);

test/parallel/test-url-pathtofileurl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ const url = require('url');
2121
assert.ok(fileURL.includes('%25'));
2222
}
2323

24+
{
25+
assert.throws(() => {
26+
url.pathToFileURL('\\\\exa mple\\share\\file.txt', { windows: true });
27+
}, {
28+
code: 'ERR_INVALID_URL',
29+
});
30+
}
31+
2432
{
2533
if (isWindows) {
2634
// UNC path: \\server\share\resource

0 commit comments

Comments
 (0)