Skip to content

Commit 734323d

Browse files
cjihrigrvagg
authored andcommitted
buffer: stop alloc() uninitialized memory return
CVE-2018-7166 Discovered by ChALkeR - Сковорода Никита Андреевич Prevent Buffer.alloc(size, fill, number) from returning uninitialized memory. Fixes: nodejs-private/security#202 PR-URL: nodejs-private/node-private#137 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 2c4c17b commit 734323d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/buffer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ function assertSize(size) {
278278
Buffer.alloc = function alloc(size, fill, encoding) {
279279
assertSize(size);
280280
if (fill !== undefined && fill !== 0 && size > 0) {
281-
return _fill(createUnsafeBuffer(size), fill, encoding);
281+
const buf = createUnsafeBuffer(size);
282+
return _fill(buf, fill, 0, buf.length, encoding);
282283
}
283284
return new FastBuffer(size);
284285
};

test/parallel/test-buffer-alloc.js

+7
Original file line numberDiff line numberDiff line change
@@ -1039,3 +1039,10 @@ common.expectsError(() => {
10391039
code: 'ERR_INVALID_ARG_VALUE',
10401040
type: TypeError
10411041
});
1042+
1043+
common.expectsError(() => {
1044+
Buffer.alloc(40, 'x', 20);
1045+
}, {
1046+
code: 'ERR_INVALID_ARG_TYPE',
1047+
type: TypeError
1048+
});

0 commit comments

Comments
 (0)