From f7191cdb309846239646bcf53d296c9a819f6875 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 29 Oct 2026 17:04:01 +0100 Subject: [PATCH] fix(canbootloader): bound the BeginFirmwareUpdate length and the progress math (#29485) wait_for_beginfirmwareupdate() subtracted the source_node_id field from the received length without checking the request was that long, so an empty request wrapped the firmware path length to SIZE_MAX and the following GetInfo and Read requests were built from far past the path buffer. Keep waiting until a request long enough to hold the field arrives. The programming progress divided by fw_image_size / 100, which is zero for images under 100 bytes, and an image down to the size of the app descriptor is accepted. Scale the offset instead. Reported by @doridoriJJ. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes --- platforms/nuttx/src/canbootloader/uavcan/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platforms/nuttx/src/canbootloader/uavcan/main.c b/platforms/nuttx/src/canbootloader/uavcan/main.c index 015943f0e9e..c62ff177dc5 100644 --- a/platforms/nuttx/src/canbootloader/uavcan/main.c +++ b/platforms/nuttx/src/canbootloader/uavcan/main.c @@ -611,6 +611,11 @@ static uavcan_error_t wait_for_beginfirmwareupdate(bl_timer_id tboot, uavcan_Pat status = uavcan_rx_dsdl(DSDLReqBeginFirmwareUpdate, &protocol, (uint8_t *) &request, &rx_length, UavcanServiceTimeOutMs); + + /* A request too short to hold source_node_id would underflow the path length below */ + if (status == UavcanOk && rx_length < uavcan_byte_count(BeginFirmwareUpdate, source_node_id)) { + status = UavcanError; + } } if (UavcanOk == status) { @@ -761,7 +766,6 @@ static flash_error_t file_read_and_program(const uavcan_Path_t *fw_path, uint8_t size_t length; protocol.tail_init.u8 = 0; - int a_percent = fw_image_size / 100; do { /* reset the rate limit */ @@ -845,7 +849,7 @@ static flash_error_t file_read_and_program(const uavcan_Path_t *fw_path, uint8_t length + (length & 1)); request.offset += length; - bootloader.percentage_done = (request.offset / a_percent); + bootloader.percentage_done = (uint32_t)request.offset * 100 / fw_image_size; watchdog_pet();