From a250f0983c2ca9b2b0fd5d9a00e1d88b0e8d2480 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Sat, 28 Apr 2018 21:22:40 -0400 Subject: [PATCH] fix: a few warnings and deprecations (#1558) - c++ string copies were potentially insecure - sandboxes are now made differently --- src/darwin_list.cpp | 6 +++--- src/serialport.cpp | 2 +- test/serialport.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/darwin_list.cpp b/src/darwin_list.cpp index 8141bc321..5aeaadfdf 100644 --- a/src/darwin_list.cpp +++ b/src/darwin_list.cpp @@ -157,7 +157,7 @@ static stDeviceListItem* GetSerialDevices() { if (result) { stDeviceListItem *deviceListItem = reinterpret_cast( malloc(sizeof(stDeviceListItem))); stSerialDevice *serialDevice = &(deviceListItem->value); - snprintf(serialDevice->port, sizeof(serialDevice->port), bsdPath); + snprintf(serialDevice->port, sizeof(serialDevice->port), "%s", bsdPath); memset(serialDevice->locationId, 0, sizeof(serialDevice->locationId)); memset(serialDevice->vendorId, 0, sizeof(serialDevice->vendorId)); memset(serialDevice->productId, 0, sizeof(serialDevice->productId)); @@ -199,7 +199,7 @@ static stDeviceListItem* GetSerialDevices() { kCFStringEncodingUTF8); if (result) { - snprintf(serialDevice->manufacturer, sizeof(serialDevice->manufacturer), manufacturer); + snprintf(serialDevice->manufacturer, sizeof(serialDevice->manufacturer), "%s", manufacturer); } CFRelease(manufacturerAsCFString); @@ -222,7 +222,7 @@ static stDeviceListItem* GetSerialDevices() { kCFStringEncodingUTF8); if (result) { - snprintf(serialDevice->serialNumber, sizeof(serialDevice->serialNumber), serialNumber); + snprintf(serialDevice->serialNumber, sizeof(serialDevice->serialNumber), "%s", serialNumber); } CFRelease(serialNumberAsCFString); diff --git a/src/serialport.cpp b/src/serialport.cpp index ebca44961..d6c7ddcb4 100644 --- a/src/serialport.cpp +++ b/src/serialport.cpp @@ -54,7 +54,7 @@ NAN_METHOD(Open) { } OpenBaton* baton = new OpenBaton(); - snprintf(baton->path, sizeof(baton->path), *path); + snprintf(baton->path, sizeof(baton->path), "%s", *path); baton->baudRate = getIntFromObject(options, "baudRate"); baton->dataBits = getIntFromObject(options, "dataBits"); baton->parity = ToParityEnum(getStringFromObj(options, "parity")); diff --git a/test/serialport.js b/test/serialport.js index 2079f5121..5c2f853bf 100644 --- a/test/serialport.js +++ b/test/serialport.js @@ -13,7 +13,7 @@ describe('SerialPort', () => { beforeEach(() => { SerialPort.Binding = mockBinding; - sandbox = sinon.sandbox.create(); + sandbox = sinon.createSandbox(); mockBinding.createPort('/dev/exists', { echo: true, readyData: new Buffer(0) }); });