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 <brendan.le.foll@intel.com>
This commit is contained in:
@@ -11,11 +11,17 @@
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
%typemap(in) (const uint8_t *data, int length) {
|
%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);
|
$1 = (uint8_t*) node::Buffer::Data($input);
|
||||||
$2 = node::Buffer::Length($input);
|
$2 = node::Buffer::Length($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in) (uint8_t *txBuf, int length) {
|
%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);
|
$1 = (uint8_t*) node::Buffer::Data($input);
|
||||||
$2 = node::Buffer::Length($input);
|
$2 = node::Buffer::Length($input);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user