This is an automated email from Gerrit. "Grant Ramsay <grant.ram...@hotmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8419
-- gerrit commit de08db2acf96f293182ff6fa9b0bc607a8ef5846 Author: Grant Ramsay <grant.ram...@hotmail.com> Date: Fri Jul 26 20:39:20 2024 +1200 target: arm_dap: Fix crash in 'dap info' command The 'dap info' command was not checking that the target was an ARM before dereferencing the `arm` pointer. This would cause a crash if the current target was (say) a mem_ap. Add 'target_to_dap' function to safely get the dap Change-Id: I530b37dafc41a4cb909e7c1ab3289e590c34cdb6 Signed-off-by: Grant Ramsay <grant.ram...@hotmail.com> diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index 9f4afae743..56377203b9 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -428,6 +428,16 @@ static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return dap_create(&goi); } +static struct adiv5_dap *target_to_dap(const struct target *target) +{ + struct adiv5_private_config *pc = target->private_config; + + if (!target->has_dap || !target->dap_configured || !pc) + return NULL; + + return pc->dap; +} + COMMAND_HANDLER(handle_dap_names) { if (CMD_ARGC != 0) @@ -448,12 +458,11 @@ COMMAND_HANDLER(handle_dap_init) COMMAND_HANDLER(handle_dap_info_command) { struct target *target = get_current_target(CMD_CTX); - struct arm *arm = target_to_arm(target); - struct adiv5_dap *dap = arm->dap; + struct adiv5_dap *dap = target_to_dap(target); uint64_t apsel; if (!dap) { - LOG_ERROR("DAP instance not available. Probably a HLA target..."); + command_print(CMD, "target %s has no DAP", target_name(target)); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } --