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 <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 2c4c17b commit 734323d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

‎lib/buffer.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ function assertSize(size){
278278
Buffer.alloc=functionalloc(size,fill,encoding){
279279
assertSize(size);
280280
if(fill!==undefined&&fill!==0&&size>0){
281-
return_fill(createUnsafeBuffer(size),fill,encoding);
281+
constbuf=createUnsafeBuffer(size);
282+
return_fill(buf,fill,0,buf.length,encoding);
282283
}
283284
returnnewFastBuffer(size);
284285
};

‎test/parallel/test-buffer-alloc.js‎

Lines changed: 7 additions & 0 deletions
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)