blackmagic-debug / blackmagic

In application debugger for ARM Cortex microcontrollers.
GNU General Public License v3.0
3.13k stars 759 forks source link

Fix remaining length calculation for 'X' 'M' and 'vFlashWrite' #1804

Closed TechnoMancer closed 2 months ago

TechnoMancer commented 2 months ago

Detailed description

When removing use of sscanf from gdb_main the calculation of the length of the remaining data portion of the 'X', 'M', and 'vFlashWrite' packet types was done wrongly. The difference between the start of data pointer and start of buffer pointer was reversed resulting in adding this to the total length rather than subtracting it. For the 'X' and 'M' packets this causes them to accept lengths longer than the supplied data but correct packets would still function as expected. For the 'vFlashWrite' packet the length passed to the flash write function was about 8 larger than it should have been which could cause problems.

The calculation of the data length portion of the packets has been corrected so all three now work as expected.

Tested vFlashWrite with '-v 2' on BMDA to confirm the correct lengths. Tested the 'M' and 'X' packets on both BMDA and native firmware by attempting packets with overly long length field for how much data is present and checking that they fail now while the correct length produces no errors.

Your checklist for this pull request

Closing issues