]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
gdbstub: fix off-by-one in gdb_handle_packet()
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>
Sun, 8 Apr 2018 14:59:33 +0000 (11:59 -0300)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 9 Apr 2018 13:18:39 +0000 (14:18 +0100)
memtohex() adds an extra trailing NUL character.

Reported-by: AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20180408145933.1149-1-f4bug@amsat.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
gdbstub.c

index a76b2fa481acd318adf338909a6cf7e5a120af81..3c3807358c843d64cb9326c6b544890919c603f6 100644 (file)
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -507,6 +507,7 @@ static inline int tohex(int v)
         return v - 10 + 'a';
 }
 
+/* writes 2*len+1 bytes in buf */
 static void memtohex(char *buf, const uint8_t *mem, int len)
 {
     int i, c;
@@ -999,8 +1000,8 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
     const char *p;
     uint32_t thread;
     int ch, reg_size, type, res;
-    char buf[MAX_PACKET_LENGTH];
     uint8_t mem_buf[MAX_PACKET_LENGTH];
+    char buf[sizeof(mem_buf) + 1 /* trailing NUL */];
     uint8_t *registers;
     target_ulong addr, len;