Skip to content

Commit 76b2c40

Browse files
trevnorrisrvagg
authored andcommitted
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 e849641 commit 76b2c40

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/buffer.js

+4
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

+8
Original file line numberDiff line numberDiff line change
@@ -1181,3 +1181,11 @@ Buffer.poolSize = ps;
11811181
assert.throws(function() {
11821182
Buffer(10).copy();
11831183
});
1184+
1185+
assert.throws(function() {
1186+
new Buffer();
1187+
}, /must start with number, buffer, array or string/);
1188+
1189+
assert.throws(function() {
1190+
new Buffer(null);
1191+
}, /must start with number, buffer, array or string/);

0 commit comments

Comments
 (0)