gdb_server: prevent false positive valgrind report 20/4420/2
authorTomas Vanek <vanekt@fbl.cz>
Fri, 16 Feb 2018 10:58:10 +0000 (11:58 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Thu, 15 Mar 2018 17:10:33 +0000 (17:10 +0000)
Change-Id: Ia59fdf8a23043889840122859b0c5bdb5f757703
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4420
Tested-by: jenkins
src/server/gdb_server.c

index c521769..2acebe8 100644 (file)
@@ -2442,7 +2442,11 @@ static int gdb_get_thread_list_chunk(struct target *target, char **thread_list,
        else
                transfer_type = 'l';
 
-       *chunk = malloc(length + 2);
+       *chunk = malloc(length + 2 + 3);
+    /* Allocating extra 3 bytes prevents false positive valgrind report
+        * of strlen(chunk) word access:
+        * Invalid read of size 4
+        * Address 0x4479934 is 44 bytes inside a block of size 45 alloc'd */
        if (*chunk == NULL) {
                LOG_ERROR("Unable to allocate memory");
                return ERROR_FAIL;