From ccd64090bb9c7aa4bad90168ad376fc8db6a0cd1 Mon Sep 17 00:00:00 2001 From: Joe Ross Date: Sun, 16 Nov 2014 10:36:44 -0800 Subject: [PATCH] Fix write when used with long byte array. If the byte array allocated is longer then the count passed to the write method, there will be a buffer overflow exception. Only put the number of bytes specified by count. Change-Id: I10ff48d5a5cf3f82c4e4e347326be033db300cdb --- .../src/main/java/edu/wpi/first/wpilibj/SerialPort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java index ed2d0926a9..a88eed6145 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java @@ -378,7 +378,7 @@ public class SerialPort { ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); ByteBuffer dataToSendBuffer = ByteBuffer.allocateDirect(count); - dataToSendBuffer.put(buffer); + dataToSendBuffer.put(buffer, 0, count); int retVal = SerialPortJNI.serialWrite(m_port, dataToSendBuffer, count, status.asIntBuffer()); HALUtil.checkStatus(status.asIntBuffer()); return retVal;