mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-28 19:21:03 +08:00
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 <julian@oes.ch>
This commit is contained in:
1 parent
37a23b6215
commit
f7191cdb30
1 file changed
+6
-2
@@ -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();
|
||||
|
||||
|
||||
Reference in new issue
Block a user