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: nodejs#2194
  • Loading branch information
trevnorris committed Jul 22, 2015
1 parent 3beae2c commit cf0bec6
Show file tree
Hide file tree
Showing 2 changed files with 8 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
4 changes: 4 additions & 0 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,3 +1179,7 @@ Buffer.poolSize = ps;
assert.throws(function() {
Buffer(10).copy();
});

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

0 comments on commit cf0bec6

Please sign in to comment.