From: Mathias K Date: Tue, 13 Mar 2012 20:26:20 +0000 (+0100) Subject: gdb_server: sanity check the gdb register size X-Git-Tag: v0.6.0-rc1~184 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4a29a4a86d4ec3e12a9494371c80ace1b8ebedab;p=openocd gdb_server: sanity check the gdb register size This patch checks the received register length with the local configured register length and disconnect on a length missmatch. Change-Id: I6b112c6b55a9ffb4526f582a384ffa91dc8b792f Signed-off-by: Mathias K Reviewed-on: http://openocd.zylin.com/517 Tested-by: jenkins Reviewed-by: Spencer Oliver --- diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 238273bb..332f74a2 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -1137,7 +1137,10 @@ static int gdb_set_register_packet(struct connection *connection, bin_buf = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8)); int chars = (DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2); - /* fix!!! add some sanity checks on packet size here */ + if ((unsigned int)chars != strlen(separator + 1)) { + LOG_ERROR("gdb sent a packet with wrong register size"); + return ERROR_SERVER_REMOTE_CLOSED; + } gdb_target_to_reg(target, separator + 1, chars, bin_buf);