src: do not pass user input to format string

PR-URL: https://github.com/nodejs/node/pull/48973
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Antoine du Hamel authored and RafaelGSS committed 2023-08-17 08:35:57 -03:00
1 parent 9138b78bcb
commit 7b9adff0be
2 files changed
+12 -3

No files matched your search

+4 -3
View File
@@ -3079,10 +3079,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
return;
}
std::string err_module_message =
"Cannot find package '" + module_path + "' imported from " + module_base;
env->isolate()->ThrowException(
ERR_MODULE_NOT_FOUND(env->isolate(), err_module_message.c_str()));
ERR_MODULE_NOT_FOUND(env->isolate(),
"Cannot find package '%s' imported from %s",
module_path,
module_base));
}
void BindingData::MemoryInfo(MemoryTracker* tracker) const {
@@ -133,6 +133,14 @@ describe('legacyMainResolve', () => {
);
});
it('should not crash when cannot resolve to a file that contains special chars', () => {
const packageJsonUrl = pathToFileURL('/c/file%20with%20percents/package.json');
assert.throws(
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
{ code: 'ERR_MODULE_NOT_FOUND' },
);
});
it('should throw when cannot resolve to a file (base not defined)', () => {
const packageJsonUrl = pathToFileURL(
path.resolve(