Fix buffer length curtailing

Thislen is the payload of the received data, which should not exceed the
buffer length minus 4 bytes header.
This commit is contained in:
stefanrueger
2026-08-14 23:00:22 +02:00
parent 979f0fadfc
commit 221ca8ef43

View File

@@ -758,9 +758,9 @@ static int jtag3_edbg_recv_frame(const PROGRAMMER *pgm, unsigned char **msg) {
int thislen = (buf[2] << 8) | buf[3];
if(thislen > rv + 4) {
pmsg_notice("%s(): unexpected length value (%d > %d)\n", __func__, thislen, rv + 4);
thislen = rv + 4;
if(thislen > rv - 4) {
pmsg_notice("%s(): unexpected length (%d > %d)\n", __func__, thislen, rv - 4);
thislen = rv - 4;
}
if(len + thislen > USBDEV_MAX_XFER_3) {
pmsg_notice("%s(): length exceeds max size (%d > %d)\n", __func__, len + thislen, USBDEV_MAX_XFER_3);