Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a25fc8

Browse filesBrowse files
NickNasoaduh95
authored andcommitted
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 900dc75 commit 9a25fc8
Copy full SHA for 9a25fc8

2 files changed

+13-2Lines changed: 13 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_url.cc‎

Copy file name to clipboardExpand all lines: src/node_url.cc
+5-2Lines 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);
Collapse file

‎test/parallel/test-url-pathtofileurl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-url-pathtofileurl.js
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.