Fix binary msg read edge cases

This commit is contained in:
Allen Hill
2026-05-15 21:39:01 +00:00
parent b510eaaef8
commit e5797b598a
2 changed files with 14 additions and 1 deletions
+11
View File
@@ -1168,6 +1168,7 @@ uint8_t AVCLAN_parseframe(const uint8_t *bytes, uint8_t len,
enum : uint8_t {
TOO_SHORT = 0x01,
MISMATCH_LENGTH,
LENGTH_TOO_BIG,
} errno;
uint8_t val;
} err = {0};
@@ -1186,6 +1187,12 @@ uint8_t AVCLAN_parseframe(const uint8_t *bytes, uint8_t len,
frame->control = *bytes++;
frame->length = *bytes++;
if (frame->length > MAXMSGLEN) {
err.errno = LENGTH_TOO_BIG;
err.val = frame->length;
goto handle_err;
}
if ((bytes + frame->length) <= last) {
memcpy(frame->data, bytes, frame->length);
} else {
@@ -1203,6 +1210,10 @@ uint8_t AVCLAN_parseframe(const uint8_t *bytes, uint8_t len,
case MISMATCH_LENGTH:
RS232_Print("frame->length is longer than remaining data");
break;
case LENGTH_TOO_BIG:
RS232_Print("frame->length exceeds MAXMSGLEN: 0x");
RS232_PrintHex8(err.val);
break;
default: break;
}
RS232_Print("\n");