buffer: fix copy() segfault with zero arguments
authorTrevor Norris <trev.norris@gmail.com>
Fri, 24 Apr 2015 16:50:15 +0000 (10:50 -0600)
committerTrevor Norris <trev.norris@gmail.com>
Fri, 24 Apr 2015 17:27:57 +0000 (11:27 -0600)
commit5404cbc74533e2d52861221201b166e7c9c015ec
tree22649946c04956981e87baf6188fde8c2b6d7602
parent2f6986ee4693b2001f34c98957f337f0cff6204d
buffer: fix copy() segfault with zero arguments

Buffer#copy() immediately does a ToObject() on the first argument before
it checks if it's even an Object. This causes
Object::HasIndexedPropertiesInExternalArrayData() to be run on nothing,
triggering the segfault. Instead run HasInstance() on the args Value.
Which will check if it's actually an Object, before checking if it
contains data.

Fixes: https://github.com/iojs/io.js/issues/1519
PR-URL: https://github.com/iojs/io.js/pull/1520
Reviewed-by: Evan Lucas <evanlucas@me.com>
src/node_buffer.cc
test/parallel/test-buffer.js