forked from auracaster/openocd
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: I0c765f915f2ef7b9a7d20c934e144559ca4e5f1c Signed-off-by: Grant Ramsay <grant.ramsay@hotmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8415 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
committed by
Antonio Borneo
parent
92b482af50
commit
db34f6f0a7
@@ -412,6 +412,16 @@ err:
|
||||
return retval;
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -432,12 +442,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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user