From 0419b14b33ecc88dc479a90074fa0d11487726ba Mon Sep 17 00:00:00 2001 From: Rajaram Gaunker Date: Fri, 16 Jun 2017 23:22:22 -0700 Subject: [PATCH 1/4] 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: https://github.com/nodejs/node/issues/13787 --- test/parallel/test-require-exceptions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/parallel/test-require-exceptions.js b/test/parallel/test-require-exceptions.js index 57d0e9c218e206..0be6b633bf9ed4 100644 --- a/test/parallel/test-require-exceptions.js +++ b/test/parallel/test-require-exceptions.js @@ -33,6 +33,11 @@ assert.throws(function() { require(`${common.fixturesDir}/throws_error`); }, /^Error: blah$/); +// Requiring the module with null character +assert.throws(function() { + require('../\u0000on'); +}, /^Error: blah$/); //TODO: Fix the acual error + // Requiring a module that does not exist should throw an // error with its `code` set to MODULE_NOT_FOUND assertModuleNotFound('/DOES_NOT_EXIST'); From 96cbbea806611fcc928829c64ffaf27280362c2e Mon Sep 17 00:00:00 2001 From: Rajaram Gaunker Date: Mon, 19 Jun 2017 01:02:55 -0700 Subject: [PATCH 2/4] 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: https://github.com/nodejs/node/issues/13787 --- lib/module.js | 2 ++ test/parallel/test-require-exceptions.js | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/module.js b/lib/module.js index ae6f4ff453ccc7..56f500b274dbf4 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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); }; diff --git a/test/parallel/test-require-exceptions.js b/test/parallel/test-require-exceptions.js index 0be6b633bf9ed4..70832d29589428 100644 --- a/test/parallel/test-require-exceptions.js +++ b/test/parallel/test-require-exceptions.js @@ -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 From 0861c3bfab5098d6b4e895e3a7f1166fa740a1ac Mon Sep 17 00:00:00 2001 From: Rajaram Gaunker Date: Tue, 20 Jun 2017 00:08:11 -0700 Subject: [PATCH 3/4] 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: https://github.com/nodejs/node/issues/13787 --- lib/module.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/module.js b/lib/module.js index 56f500b274dbf4..60a85524e2132f 100644 --- a/lib/module.js +++ b/lib/module.js @@ -511,7 +511,9 @@ 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]; + if (path.indexOf('\u0000') != -1) { + path = path.split('\u0000')[0]; + } return Module._load(path, this, /* isMain */ false); }; From 01c5127160c434e9eba2d33ffc4f79fc31b7f81c Mon Sep 17 00:00:00 2001 From: Rajaram Gaunker Date: Tue, 20 Jun 2017 09:38:09 -0700 Subject: [PATCH 4/4] 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: https://github.com/nodejs/node/issues/13787 --- lib/module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/module.js b/lib/module.js index 60a85524e2132f..44a3d0ff31ab13 100644 --- a/lib/module.js +++ b/lib/module.js @@ -511,7 +511,7 @@ 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 - if (path.indexOf('\u0000') != -1) { + if (path.indexOf('\u0000') !== -1) { path = path.split('\u0000')[0]; } return Module._load(path, this, /* isMain */ false);