src: detect nul bytes in InternalModuleReadFile()

Throw an exception when the path contains nul bytes, don't abort.

Fixes: https://github.com/nodejs/node/issues/13787
PR-URL: https://github.com/nodejs/node/pull/14854
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Ben Noordhuis 2017-08-16 11:46:55 +02:00 committed by Anna Henningsen
parent 6a0e3b16f3
commit ffed7b6e66
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
2 changed files with 12 additions and 0 deletions

View File

@ -503,6 +503,9 @@ static void InternalModuleReadFile(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsString()); CHECK(args[0]->IsString());
node::Utf8Value path(env->isolate(), args[0]); node::Utf8Value path(env->isolate(), args[0]);
if (strlen(*path) != path.length())
return; // Contains a nul byte.
uv_fs_t open_req; uv_fs_t open_req;
const int fd = uv_fs_open(loop, &open_req, *path, O_RDONLY, 0, nullptr); const int fd = uv_fs_open(loop, &open_req, *path, O_RDONLY, 0, nullptr);
uv_fs_req_cleanup(&open_req); uv_fs_req_cleanup(&open_req);

View File

@ -0,0 +1,9 @@
'use strict';
require('../common');
const assert = require('assert');
// Nul bytes should throw, not abort.
assert.throws(() => require('\u0000ab'), /Cannot find module '\u0000ab'/);
assert.throws(() => require('a\u0000b'), /Cannot find module 'a\u0000b'/);
assert.throws(() => require('ab\u0000'), /Cannot find module 'ab\u0000'/);