From 55533ed8c1eb68675dcdd1e4d1277c51d8c4b9f1 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Wed, 20 May 2015 11:16:15 +0100 Subject: [PATCH] mraajs.i: add buffer checks to python write() typemaps in Spi & I2c Previously anything passed to an I2c::write() or Spi::write() function in node.js that wasn't a node::Buffer or an object would likely cause a segfault later on during future calls. This change calls node::Buffer::HasInstance(obj) to make sure the buffer is valid prior to grabbing it's data Signed-off-by: Brendan Le Foll --- src/javascript/mraajs.i | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/javascript/mraajs.i b/src/javascript/mraajs.i index b872f0c..a66275a 100644 --- a/src/javascript/mraajs.i +++ b/src/javascript/mraajs.i @@ -11,11 +11,17 @@ %} %typemap(in) (const uint8_t *data, int length) { + if (!node::Buffer::HasInstance($input)) { + SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer"); + } $1 = (uint8_t*) node::Buffer::Data($input); $2 = node::Buffer::Length($input); } %typemap(in) (uint8_t *txBuf, int length) { + if (!node::Buffer::HasInstance($input)) { + SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer"); + } $1 = (uint8_t*) node::Buffer::Data($input); $2 = node::Buffer::Length($input); }