Adds additional checks for parser (#15165)

Signed-off-by: Ben Rosenblum <rosenblumb@gmail.com>
This commit is contained in:
morph166955 2023-07-12 15:02:45 -05:00 committed by GitHub
parent 7587e0c504
commit 80eeba48ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 74 additions and 59 deletions

View File

@ -96,28 +96,39 @@ public class ShieldTVMessageParser {
callback.setHostName(encHostname);
} else if (msg.startsWith(MESSAGE_HOSTNAME)) {
// Longer hostname reply
// 080b 12 5b08b510 12 TOTALLEN? 0a LEN Hostname 12 LEN IPADDR Padding? 22 LEN DeviceID 2a LEN arm64-v8a
// 080b 12 5b08b510 12 TOTALLEN? 0a LEN Hostname 12 LEN IPADDR 18 9b46 22 LEN DeviceID 2a LEN arm64-v8a
// 2a LEN armeabi-v7a 2a LEN armeabi 180b
// It's possible for there to be more or less of the arm lists
logger.trace("{} - Longer Hostname Reply", thingId);
int i = 20;
int i = 18;
int length;
int current;
// Hostname
StringBuilder hostname = new StringBuilder();
StringBuilder ipAddress = new StringBuilder();
StringBuilder deviceId = new StringBuilder();
StringBuilder arch = new StringBuilder();
String st = "" + charArray[i] + "" + charArray[i + 1];
if (DELIMITER_0A.equals(st)) {
i += 2; // 0a
// Hostname
st = "" + charArray[i] + "" + charArray[i + 1];
length = Integer.parseInt(st, 16) * 2;
i += 2;
StringBuilder hostname = new StringBuilder();
current = i;
for (; i < current + length; i = i + 2) {
st = "" + charArray[i] + "" + charArray[i + 1];
hostname.append(st);
}
}
st = "" + charArray[i] + "" + charArray[i + 1];
if (DELIMITER_12.equals(st)) {
i += 2; // 12
// ipAddress
@ -125,20 +136,24 @@ public class ShieldTVMessageParser {
length = Integer.parseInt(st, 16) * 2;
i += 2;
StringBuilder ipAddress = new StringBuilder();
current = i;
for (; i < current + length; i = i + 2) {
st = "" + charArray[i] + "" + charArray[i + 1];
ipAddress.append(st);
}
}
st = "" + charArray[i] + "" + charArray[i + 1];
if (DELIMITER_18.equals(st)) {
while (!DELIMITER_22.equals(st)) {
i += 2;
st = "" + charArray[i] + "" + charArray[i + 1];
}
}
st = "" + charArray[i] + "" + charArray[i + 1];
if (DELIMITER_22.equals(st)) {
i += 2; // 22
// deviceId
@ -147,17 +162,17 @@ public class ShieldTVMessageParser {
length = Integer.parseInt(st, 16) * 2;
i += 2;
StringBuilder deviceId = new StringBuilder();
current = i;
for (; i < current + length; i = i + 2) {
st = "" + charArray[i] + "" + charArray[i + 1];
deviceId.append(st);
}
}
// architectures
st = "" + charArray[i] + "" + charArray[i + 1];
StringBuilder arch = new StringBuilder();
if (DELIMITER_2A.equals(st)) {
while (DELIMITER_2A.equals(st)) {
i += 2;
st = "" + charArray[i] + "" + charArray[i + 1];
@ -173,7 +188,7 @@ public class ShieldTVMessageParser {
arch.append("2c");
}
}
}
String encHostname = ShieldTVRequest.encodeMessage(hostname.toString());
String encIpAddress = ShieldTVRequest.encodeMessage(ipAddress.toString());
String encDeviceId = ShieldTVRequest.encodeMessage(deviceId.toString());