buffer: stop alloc() uninitialized memory return
CVE-2018-7166 Discovered by ChALkeR - Сковорода Никита Андреевич Prevent Buffer.alloc(size, fill, number) from returning uninitialized memory. Fixes: https://github.com/nodejs-private/security/issues/202 PR-URL: https://github.com/nodejs-private/node-private/pull/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>
This commit is contained in:
parent
16accff90f
commit
40a7beedda
@ -278,7 +278,8 @@ function assertSize(size) {
|
||||
Buffer.alloc = function alloc(size, fill, encoding) {
|
||||
assertSize(size);
|
||||
if (fill !== undefined && fill !== 0 && size > 0) {
|
||||
return _fill(createUnsafeBuffer(size), fill, encoding);
|
||||
const buf = createUnsafeBuffer(size);
|
||||
return _fill(buf, fill, 0, buf.length, encoding);
|
||||
}
|
||||
return new FastBuffer(size);
|
||||
};
|
||||
|
@ -1039,3 +1039,10 @@ common.expectsError(() => {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
type: TypeError
|
||||
});
|
||||
|
||||
common.expectsError(() => {
|
||||
Buffer.alloc(40, 'x', 20);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user