Skip to content

Commit 5e409c2

Browse files
committed
makeFastBuffer should not segfault but rather throw on non-buffer
1 parent f4e69e4 commit 5e409c2

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/node_buffer.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,11 @@ Handle<Value> Buffer::ByteLength(const Arguments &args) {
679679
Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
680680
HandleScope scope;
681681

682+
if (!Buffer::HasInstance(args[0])) {
683+
return ThrowException(Exception::TypeError(String::New(
684+
"First argument must be a Buffer")));
685+
}
686+
682687
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
683688
Local<Object> fast_buffer = args[1]->ToObject();;
684689
uint32_t offset = args[2]->Uint32Value();

test/simple/test-buffer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,7 @@ assert.equal(0xee, b[0]);
520520
assert.equal(0xad, b[1]);
521521
assert.equal(0xbe, b[2]);
522522
assert.equal(0xef, b[3]);
523+
524+
525+
// This should not segfault the program.
526+
new Buffer('"pong"', 0, 6, 8031, '127.0.0.1')

0 commit comments

Comments
 (0)