Skip to content

Commit

Permalink
module: ignore module path after null character
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zimbabao committed Jun 19, 2017
1 parent 0419b14 commit 96cbbea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ Module.prototype.load = function(filename) {
Module.prototype.require = function(path) {
assert(path, 'missing path');
assert(typeof path === 'string', 'path must be a string');
// Ignore part of the path after null character if it exists
path = path.split('\u0000')[0];
return Module._load(path, this, /* isMain */ false);
};

Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-require-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ assert.throws(function() {
require(`${common.fixturesDir}/throws_error`);
}, /^Error: blah$/);

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

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

0 comments on commit 96cbbea

Please sign in to comment.