From 8662041e5a76fc3f0b7a4022eb3e40840eef82ff Mon Sep 17 00:00:00 2001 From: Yukai Li Date: Sun, 4 Oct 2020 20:59:24 -0600 Subject: [PATCH] Lefun: Fix checksum generation --- .../gadgetbridge/devices/lefun/commands/BaseCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/commands/BaseCommand.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/commands/BaseCommand.java index 7a8ac77d3..486dc0b25 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/commands/BaseCommand.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lefun/commands/BaseCommand.java @@ -32,12 +32,12 @@ public abstract class BaseCommand { abstract protected byte serializeParams(ByteBuffer params); public void deserialize(byte[] response) { - if (response.length < LefunConstants.CMD_HEADER_LENGTH) + if (response.length < LefunConstants.CMD_HEADER_LENGTH || response.length < response[1]) throw new IllegalArgumentException("Response is too short"); - if (calculateChecksum(response, 0, response.length - 1) != response[response.length - 1]) + if (calculateChecksum(response, 0, response[1] - 1) != response[response[1] - 1]) throw new IllegalArgumentException("Incorrect message checksum"); ByteBuffer buffer = ByteBuffer.wrap(response, LefunConstants.CMD_HEADER_LENGTH - 1, - response.length - LefunConstants.CMD_HEADER_LENGTH); + response[1] - LefunConstants.CMD_HEADER_LENGTH); buffer.order(ByteOrder.BIG_ENDIAN); deserializeParams(response[2], buffer); }