Skip to content

Commit 96cbbea

Browse files
committed
module: ignore module path after null character
Null char as the first char as the path component of first argument of require causes a node crash. Ignoring null and all chars after that in require path. Fixes: #13787
1 parent 0419b14 commit 96cbbea

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ Module.prototype.load = function(filename) {
510510
Module.prototype.require = function(path) {
511511
assert(path, 'missing path');
512512
assert(typeof path === 'string', 'path must be a string');
513+
// Ignore part of the path after null character if it exists
514+
path = path.split('\u0000')[0];
513515
return Module._load(path, this, /* isMain */ false);
514516
};
515517

test/parallel/test-require-exceptions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ assert.throws(function() {
3333
require(`${common.fixturesDir}/throws_error`);
3434
}, /^Error: blah$/);
3535

36-
// Requiring the module with null character
36+
// Requiring the module with null character in
37+
// path as first character of a component
3738
assert.throws(function() {
3839
require('../\u0000on');
39-
}, /^Error: blah$/); //TODO: Fix the acual error
40+
}, /^Error: Cannot find module '[.]{2}\/'$/);
4041

4142
// Requiring a module that does not exist should throw an
4243
// error with its `code` set to MODULE_NOT_FOUND

0 commit comments

Comments
 (0)