Harden packet, retry, and alert handling

This commit is contained in:
mikecarper committed 2026-07-13 16:37:32 -07:00
1 parent b8f438d6ea
commit e3f47b487b
20 files changed
+451 -143

No files matched your search

+8 -1
View File
@@ -64,22 +64,29 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
}
bool Packet::readFrom(const uint8_t src[], uint8_t len) {
if (src == NULL || len < 2) return false; // header + path_len
uint8_t i = 0;
tx_cr = 0;
header = src[i++];
if (getPayloadVer() > PAYLOAD_VER_1) return false;
if (hasTransportCodes()) {
if ((uint16_t)i + sizeof(transport_codes) + 1 > len) return false;
memcpy(&transport_codes[0], &src[i], 2); i += 2;
memcpy(&transport_codes[1], &src[i], 2); i += 2;
} else {
transport_codes[0] = transport_codes[1] = 0;
}
if (i >= len) return false;
path_len = src[i++];
if (!isValidPathLen(path_len)) return false; // bad encoding
uint8_t bl = getPathByteLen();
if ((uint16_t)i + bl > len) return false;
memcpy(path, &src[i], bl); i += bl;
if (i >= len) return false; // bad encoding
payload_len = len - i;
if (payload_len > sizeof(payload)) return false; // bad encoding
memcpy(payload, &src[i], payload_len); //i += payload_len;