Skip to content

Commit 1ec691e

Browse files
committed
url: process crash via malformed UNC hostname in pathToFileURL()
Fixes: #62546
1 parent 5ff1eab commit 1ec691e

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/node_url.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo<Value>& args) {
169169
[[unlikely]] {
170170
CHECK(args[2]->IsString());
171171
Utf8Value hostname(isolate, args[2]);
172-
CHECK(out->set_hostname(hostname.ToStringView()));
172+
if (!out->set_hostname(hostname.ToStringView())) {
173+
return ThrowInvalidURL(
174+
realm->env(), input.ToStringView(), 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)