aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Robertson <danlrobertson89@gmail.com>2018-05-22 02:44:01 +0000
committerDan Robertson <danlrobertson89@gmail.com>2018-05-22 02:57:16 +0000
commit0493ff81a1057d299076ee585e79d1b0e0a2fe21 (patch)
treea979c63b2615372ab148c4d3c6c5bc8a14433368
parentbb86173f37c11d1ea305b3e45d6abdaf3d239512 (diff)
downloadriscv-openocd-0493ff81a1057d299076ee585e79d1b0e0a2fe21.zip
riscv-openocd-0493ff81a1057d299076ee585e79d1b0e0a2fe21.tar.gz
riscv-openocd-0493ff81a1057d299076ee585e79d1b0e0a2fe21.tar.bz2
Fix posible null deref in get_target_type
A null deref occurs if riscv_deinit_target is called and the target has not been initialized. Change-Id: Ic34057508ed6686eb48e9fe8220110c42ba2fc5e
-rw-r--r--src/target/riscv/riscv.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index b171469..88d4b92 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -232,6 +232,11 @@ static struct target_type *get_target_type(struct target *target)
{
riscv_info_t *info = (riscv_info_t *) target->arch_info;
+ if (!info) {
+ LOG_ERROR("Target has not been initialized");
+ return NULL;
+ }
+
switch (info->dtm_version) {
case 0:
return &riscv011_target;
@@ -265,9 +270,11 @@ static void riscv_deinit_target(struct target *target)
{
LOG_DEBUG("riscv_deinit_target()");
struct target_type *tt = get_target_type(target);
- tt->deinit_target(target);
- riscv_info_t *info = (riscv_info_t *) target->arch_info;
- free(info);
+ if (tt) {
+ tt->deinit_target(target);
+ riscv_info_t *info = (riscv_info_t *) target->arch_info;
+ free(info);
+ }
target->arch_info = NULL;
}