F-5675: fix signed-overflow UB from uint8_t<<24 in serve_update version assembly

Shifting a uint8_t (int-promoted) left by 24 is undefined behaviour per C11
6.5.7p4 when the byte value is >= 0x80. Cast the MSB operand to uint32_t at
both sites (CMD_APP_VER line 391, CMD_HDR_VER line 412).

Note: the report's endian-mismatch claim is incorrect. CMD_APP_VER senders
(app_nrf52.c, app_stm32f4.c, app_stm32wb.c) all transmit version bytes
MSB-first; CMD_HDR_VER is sent LSB-first by uart_send_current_version. The
two decode expressions are intentionally asymmetric and both reconstruct the
correct version value.
pull/795/head
Daniele Lacamera 2026-06-11 18:53:49 +02:00
parent 5cec6211d2
commit 524397df70
1 changed files with 2 additions and 2 deletions

View File

@ -388,7 +388,7 @@ static void serve_update(uint8_t *base, const char *uart_dev)
idx++;
}
v = buf[4] + (buf[3] << 8) + (buf[2] << 16) + (buf[1] << 24);
v = buf[4] + (buf[3] << 8) + (buf[2] << 16) + ((uint32_t)buf[1] << 24);
printf("Boot partition version from test app: %u\n", v);
continue;
}
@ -409,7 +409,7 @@ static void serve_update(uint8_t *base, const char *uart_dev)
}
if (idx == 5) {
printf("\r\n** TARGET REBOOT **\n");
v = buf[1] + (buf[2] << 8) + (buf[3] << 16) + (buf[4] << 24);
v = buf[1] + (buf[2] << 8) + (buf[3] << 16) + ((uint32_t)buf[4] << 24);
printf("Version running on target: %u\n", v);
}
continue;