Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
zimbabao committed Jun 19, 2017
commit 96cbbea806611fcc928829c64ffaf27280362c2e
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