Skip to content

Commit

Permalink
buffer: fix missing null/undefined check
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
trevnorris committed Jul 27, 2015
1 parent 4737dcd commit 9cf36a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ function fromObject(obj) {
return b;
}

if (obj == null) {
throw new TypeError('must start with number, buffer, array or string');
}

if (obj instanceof ArrayBuffer) {
return binding.createFromArrayBuffer(obj);
}
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,3 +1179,11 @@ Buffer.poolSize = ps;
assert.throws(function() {
Buffer(10).copy();
});

assert.throws(function() {
new Buffer();
}, /must start with number, buffer, array or string/);

assert.throws(function() {
new Buffer(null);
}, /must start with number, buffer, array or string/);

0 comments on commit 9cf36a1

Please sign in to comment.