aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/drivers
diff options
context:
space:
mode:
authorMarc Schink <openocd-dev@marcschink.de>2016-05-22 19:44:27 +0200
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>2016-10-17 09:28:05 +0100
commit674141e8a7a6413cb803d90c2a20150260015f81 (patch)
tree62296ce0bfefecce10134718de8c4a81c5cb50ef /src/jtag/drivers
parent10aeff925936a43e873acfd0068b1eea03781051 (diff)
helper: Make unhexify() robust on invalid data
The current implementation is not suitable for user provided data because it does not detect invalid inputs in many cases. For example, the string "aa0xbb" is successfully converted to the 3 bytes: 0xaa, 0x00 and 0xbb. An other example is "aabi" which is successfully converted to the 2 bytes: 0xaa and 0x0b. Both are obviously incorrect. Make unhexify() robust on invalid data and use more appropriate data types for its parameters. Also, add a small documentation for the function. Change-Id: Idb799beb86fc608b066c8a76365021ed44c7f890 Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/3792 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/jtag/drivers')
-rw-r--r--src/jtag/drivers/ti_icdi_usb.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/jtag/drivers/ti_icdi_usb.c b/src/jtag/drivers/ti_icdi_usb.c
index 3db03b03..7a6272fd 100644
--- a/src/jtag/drivers/ti_icdi_usb.c
+++ b/src/jtag/drivers/ti_icdi_usb.c
@@ -266,7 +266,7 @@ static int icdi_get_cmd_result(void *handle)
if (h->read_buffer[offset] == 'E') {
/* get error code */
- char result;
+ uint8_t result;
if (unhexify(&result, h->read_buffer + offset + 1, 1) != 1)
return ERROR_FAIL;
return result;
@@ -328,7 +328,7 @@ static int icdi_usb_version(void *handle)
}
/* convert reply */
- if (unhexify(version, h->read_buffer + 2, 4) != 4) {
+ if (unhexify((uint8_t *)version, h->read_buffer + 2, 4) != 4) {
LOG_WARNING("unable to get ICDI version");
return ERROR_OK;
}
@@ -495,7 +495,7 @@ static int icdi_usb_read_reg(void *handle, int num, uint32_t *val)
/* convert result */
uint8_t buf[4];
- if (unhexify((char *)buf, h->read_buffer + 2, 4) != 4) {
+ if (unhexify(buf, h->read_buffer + 2, 4) != 4) {
LOG_ERROR("failed to convert result");
return ERROR_FAIL;
}