diff --git a/lib/buffer.js b/lib/buffer.js index 415f37238db7cc..c2383b6d7a032c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -22,11 +22,14 @@ 'use strict'; const binding = process.binding('buffer'); +const config = process.binding('config'); const { compare: compare_, compareOffset } = binding; const { isArrayBuffer, isSharedArrayBuffer, isUint8Array } = process.binding('util'); const bindingObj = {}; const internalUtil = require('internal/util'); +const zeroFillBuffers = !!config.zeroFillBuffers; +const randomFill = zeroFillBuffers ? 0 : Math.floor(Math.random() * 256); class FastBuffer extends Uint8Array { constructor(arg1, arg2, arg3) { @@ -102,7 +105,7 @@ function Buffer(arg, encodingOrOffset, length) { 'If encoding is specified then the first argument must be a string' ); } - return Buffer.allocUnsafe(arg); + return Buffer.allocUnsafe(arg).fill(randomFill); } return Buffer.from(arg, encodingOrOffset, length); } diff --git a/src/node_config.cc b/src/node_config.cc index 5c9c51585baf3a..8ad30afdae38db 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -1,4 +1,5 @@ #include "node.h" +#include "node_buffer.h" #include "node_i18n.h" #include "env.h" #include "env-inl.h" @@ -49,6 +50,9 @@ void InitConfig(Local target, if (config_preserve_symlinks) READONLY_BOOLEAN_PROPERTY("preserveSymlinks"); + if (zero_fill_all_buffers) + READONLY_BOOLEAN_PROPERTY("zeroFillBuffers"); + if (!config_warning_file.empty()) { Local name = OneByteString(env->isolate(), "warningFile"); Local value = String::NewFromUtf8(env->isolate(),