summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2010-01-30 22:40:50 -0800
committerDavid Brownell <dbrownell@users.sourceforge.net>2010-01-30 22:46:00 -0800
commit695666d294e7d572bc5799e0cef4fc384b28c733 (patch)
treed8ee4164fad2fe114c909356c0d2ad4528a427e1 /src
parent46b6d5bfe644b5f6a1fe50930c850f09a78b5bad (diff)
downloadopenocd+libswd-695666d294e7d572bc5799e0cef4fc384b28c733.tar.gz
openocd+libswd-695666d294e7d572bc5799e0cef4fc384b28c733.tar.bz2
openocd+libswd-695666d294e7d572bc5799e0cef4fc384b28c733.tar.xz
openocd+libswd-695666d294e7d572bc5799e0cef4fc384b28c733.zip
ADIv5 error checking for Tcl commands
Reject invalid AP numbers (256+) as Tcl operation parameters. Shrink one of the overlong lines. Add my copyright to the ADIv5 code (multiple contributions). Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Diffstat (limited to 'src')
-rw-r--r--src/target/arm_adi_v5.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c
index 0a6a7ef7..0e3b3495 100644
--- a/src/target/arm_adi_v5.c
+++ b/src/target/arm_adi_v5.c
@@ -8,6 +8,8 @@
* Copyright (C) 2009 by Oyvind Harboe *
* oyvind.harboe@zylin.com *
* *
+ * Copyright (C) 2009-2010 by David Brownell *
+ * *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
@@ -1164,7 +1166,8 @@ is_dap_cid_ok(uint32_t cid3, uint32_t cid2, uint32_t cid1, uint32_t cid0)
&& ((cid1 & 0x0f) == 0) && cid0 == 0x0d;
}
-int dap_info_command(struct command_context *cmd_ctx, struct swjdp_common *swjdp, int apsel)
+int dap_info_command(struct command_context *cmd_ctx,
+ struct swjdp_common *swjdp, int apsel)
{
uint32_t dbgbase, apid;
@@ -1172,6 +1175,10 @@ int dap_info_command(struct command_context *cmd_ctx, struct swjdp_common *swjdp
uint8_t mem_ap;
uint32_t apselold;
+ /* AP address is in bits 31:24 of DP_SELECT */
+ if (apsel >= 256)
+ return ERROR_INVALID_ARGUMENTS;
+
apselold = swjdp->apsel;
dap_ap_select(swjdp, apsel);
dap_ap_read_reg_u32(swjdp, AP_REG_BASE, &dbgbase);
@@ -1524,6 +1531,9 @@ DAP_COMMAND_HANDLER(dap_baseaddr_command)
break;
case 1:
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
+ /* AP address is in bits 31:24 of DP_SELECT */
+ if (apsel >= 256)
+ return ERROR_INVALID_ARGUMENTS;
break;
default:
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1580,6 +1590,9 @@ DAP_COMMAND_HANDLER(dap_apsel_command)
break;
case 1:
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
+ /* AP address is in bits 31:24 of DP_SELECT */
+ if (apsel >= 256)
+ return ERROR_INVALID_ARGUMENTS;
break;
default:
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1606,6 +1619,9 @@ DAP_COMMAND_HANDLER(dap_apid_command)
break;
case 1:
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
+ /* AP address is in bits 31:24 of DP_SELECT */
+ if (apsel >= 256)
+ return ERROR_INVALID_ARGUMENTS;
break;
default:
return ERROR_COMMAND_SYNTAX_ERROR;