From 674141e8a7a6413cb803d90c2a20150260015f81 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Sun, 22 May 2016 19:44:27 +0200 Subject: 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 Reviewed-on: http://openocd.zylin.com/3792 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/rtos/rtos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rtos') diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 4c99ad2..448c49c 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -213,7 +213,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s goto done; /* Decode any symbol name in the packet*/ - int len = unhexify(cur_sym, strchr(packet + 8, ':') + 1, strlen(strchr(packet + 8, ':') + 1)); + size_t len = unhexify((uint8_t *)cur_sym, strchr(packet + 8, ':') + 1, strlen(strchr(packet + 8, ':') + 1)); cur_sym[len] = 0; if ((strcmp(packet, "qSymbol::") != 0) && /* GDB is not offering symbol lookup for the first time */ -- cgit v1.1