Skip to content

Commit 9cf36a1

Browse files
committed
buffer: fix missing null/undefined check
The new implementation of Buffer missed the check for null/undefined as the first argument to new Buffer(). Reintroduce the check and add test. Fix: e8734c0 "buffer: implement Uint8Array backed Buffer" Fix: #2194 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 4737dcd commit 9cf36a1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/buffer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ function fromObject(obj) {
105105
return b;
106106
}
107107

108+
if (obj == null) {
109+
throw new TypeError('must start with number, buffer, array or string');
110+
}
111+
108112
if (obj instanceof ArrayBuffer) {
109113
return binding.createFromArrayBuffer(obj);
110114
}

test/parallel/test-buffer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,3 +1179,11 @@ Buffer.poolSize = ps;
11791179
assert.throws(function() {
11801180
Buffer(10).copy();
11811181
});
1182+
1183+
assert.throws(function() {
1184+
new Buffer();
1185+
}, /must start with number, buffer, array or string/);
1186+
1187+
assert.throws(function() {
1188+
new Buffer(null);
1189+
}, /must start with number, buffer, array or string/);

0 commit comments

Comments
 (0)