Skip to content

Commit 00bc1ea

Browse files
borneoaerhankur
authored andcommitted
gdb_server: fix segfault with GDB command 'flash-erase'
Running the GDB command 'flash-erase' triggers sending the remote GDB commands 'vFlashErase' (one per flash bank) followed by one single 'vFlashDone', with no 'vFlashWrite' commands in between. This causes the field 'gdb_connection->vflash_image' to be NULL during the execution of 'vFlashDone', triggering a segmentation fault in OpenOCD. While parsing 'vFlashDone', check if any image to flash has been received. Change-Id: I443021c7a531255b60f2c44c2685e52e3c34b5c8 Signed-off-by: Antonio Borneo <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8164 Tested-by: jenkins
1 parent 3a6e6a2 commit 00bc1ea

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/server/gdb_server.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,6 +3384,13 @@ static int gdb_v_packet(struct connection *connection,
33843384
if (strncmp(packet, "vFlashDone", 10) == 0) {
33853385
uint32_t written;
33863386

3387+
/* GDB command 'flash-erase' does not send a vFlashWrite,
3388+
* so nothing to write here. */
3389+
if (!gdb_connection->vflash_image) {
3390+
gdb_put_packet(connection, "OK", 2);
3391+
return ERROR_OK;
3392+
}
3393+
33873394
/* process the flashing buffer. No need to erase as GDB
33883395
* always issues a vFlashErase first. */
33893396
target_call_event_callbacks(target,

0 commit comments

Comments
 (0)