tests/virtio-9p: add terminating null in v9fs_string_read()
authorChristian Schoenebeck <qemu_oss@crudebyte.com>
Sat, 8 Feb 2020 08:24:19 +0000 (09:24 +0100)
committerGreg Kurz <groug@kaod.org>
Sat, 8 Feb 2020 08:24:19 +0000 (09:24 +0100)
The 9p protocol sends strings in general without null termination
over the wire. However for future use of this functions it is
beneficial for the delivered string to be null terminated though
for being able to use the string with standard C functions which
often rely on strings being null terminated.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <52c84e2ce3bcafc2a38eed13b8c8e23bc1a8ecb9.1579567019.git.qemu_oss@crudebyte.com>
Signed-off-by: Greg Kurz <groug@kaod.org>
tests/qtest/virtio-9p-test.c

index e7b58e3a0c3c4ce373b8546e9916418f12ffca6f..06263edb53f9c876ef4d7fd9c9296a4a093e32be 100644 (file)
@@ -130,8 +130,9 @@ static void v9fs_string_read(P9Req *req, uint16_t *len, char **string)
         *len = local_len;
     }
     if (string) {
-        *string = g_malloc(local_len);
+        *string = g_malloc(local_len + 1);
         v9fs_memread(req, *string, local_len);
+        (*string)[local_len] = 0;
     } else {
         v9fs_memskip(req, local_len);
     }