Skip to content

Commit 7b9adff

Browse files
aduh95RafaelGSS
authored andcommitted
src: do not pass user input to format string
PR-URL: #48973 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 9138b78 commit 7b9adff

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/node_file.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -3079,10 +3079,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
30793079
return;
30803080
}
30813081

3082-
std::string err_module_message =
3083-
"Cannot find package '" + module_path + "' imported from " + module_base;
30843082
env->isolate()->ThrowException(
3085-
ERR_MODULE_NOT_FOUND(env->isolate(), err_module_message.c_str()));
3083+
ERR_MODULE_NOT_FOUND(env->isolate(),
3084+
"Cannot find package '%s' imported from %s",
3085+
module_path,
3086+
module_base));
30863087
}
30873088

30883089
void BindingData::MemoryInfo(MemoryTracker* tracker) const {

test/es-module/test-cjs-legacyMainResolve.js

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ describe('legacyMainResolve', () => {
133133
);
134134
});
135135

136+
it('should not crash when cannot resolve to a file that contains special chars', () => {
137+
const packageJsonUrl = pathToFileURL('/c/file%20with%20percents/package.json');
138+
assert.throws(
139+
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
140+
{ code: 'ERR_MODULE_NOT_FOUND' },
141+
);
142+
});
143+
136144
it('should throw when cannot resolve to a file (base not defined)', () => {
137145
const packageJsonUrl = pathToFileURL(
138146
path.resolve(

0 commit comments

Comments
 (0)