Skip to content

Commit cf0bec6

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
1 parent 3beae2c commit cf0bec6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,3 +1179,7 @@ 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/);

0 commit comments

Comments
 (0)