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
PR-URL: #2195
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
  • Loading branch information
trevnorris authored and rvagg committed Aug 4, 2015
1 parent 2ba8b23 commit 60a974d
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 @@ -1181,3 +1181,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 60a974d

Please sign in to comment.