GeezerVison is showing github.com — src: do not pass user input to format string · nodejs/node@7b9adff
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_file.cc +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3079,10 +3079,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { |
3079 | 3079 | return; |
3080 | 3080 | } |
3081 | 3081 |
|
3082 | | - std::string err_module_message = |
3083 | | - "Cannot find package '" + module_path + "' imported from " + module_base; |
3084 | 3082 | 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)); |
3086 | 3087 | } |
3087 | 3088 |
|
3088 | 3089 | void BindingData::MemoryInfo(MemoryTracker* tracker) const { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/es-module/test-cjs-legacyMainResolve.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -133,6 +133,14 @@ describe('legacyMainResolve', () => { |
133 | 133 | ); |
134 | 134 | }); |
135 | 135 |
|
| 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 | + |
136 | 144 | it('should throw when cannot resolve to a file (base not defined)', () => { |
137 | 145 | const packageJsonUrl = pathToFileURL( |
138 | 146 | path.resolve( |
|