aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/WatchFrameDecoder.java14
-rw-r--r--test/org/traccar/protocol/WatchFrameDecoderTest.java4
2 files changed, 13 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java
index 9adea2843..f6b5ef12c 100644
--- a/src/org/traccar/protocol/WatchFrameDecoder.java
+++ b/src/org/traccar/protocol/WatchFrameDecoder.java
@@ -37,11 +37,6 @@ public class WatchFrameDecoder extends FrameDecoder {
int lengthIndex = buf.indexOf(idIndex, buf.writerIndex(), (byte) '*') + 1;
if (lengthIndex <= 0) {
return null;
- } else if (lengthIndex - idIndex > 10 + 1) {
- lengthIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*') + 1;
- if (lengthIndex <= 0) {
- return null;
- }
}
int payloadIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*');
@@ -49,6 +44,15 @@ public class WatchFrameDecoder extends FrameDecoder {
return null;
}
+ if (payloadIndex + 5 < buf.writerIndex() && buf.getByte(payloadIndex + 5) == '*'
+ && buf.toString(payloadIndex + 1, 4, StandardCharsets.US_ASCII).matches("[0-9A-F]+")) {
+ lengthIndex = payloadIndex + 1;
+ payloadIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*');
+ if (payloadIndex < 0) {
+ return null;
+ }
+ }
+
int length = Integer.parseInt(
buf.toString(lengthIndex, payloadIndex - lengthIndex, StandardCharsets.US_ASCII), 16);
if (buf.readableBytes() >= payloadIndex + 1 + length + 1) {
diff --git a/test/org/traccar/protocol/WatchFrameDecoderTest.java b/test/org/traccar/protocol/WatchFrameDecoderTest.java
index a1eca30bc..741807de2 100644
--- a/test/org/traccar/protocol/WatchFrameDecoderTest.java
+++ b/test/org/traccar/protocol/WatchFrameDecoderTest.java
@@ -11,6 +11,10 @@ public class WatchFrameDecoderTest extends ProtocolTest {
WatchFrameDecoder decoder = new WatchFrameDecoder();
verifyFrame(
+ binary("5b33472a3335323636313039303134333135302a303030412a4c4b2c302c302c3130305d"),
+ decoder.decode(null, null, binary("5b33472a3335323636313039303134333135302a303030412a4c4b2c302c302c3130305d")));
+
+ verifyFrame(
binary("5b33472a383330383430363237392a303030382a72636170747572655d"),
decoder.decode(null, null, binary("5b33472a383330383430363237392a303030382a72636170747572655d")));