9ae3a8
From 2aa26696846adf25a41fa082f4d42c98b2b05fe3 Mon Sep 17 00:00:00 2001
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
Date: Mon, 15 Feb 2016 09:28:17 +0100
9ae3a8
Subject: [PATCH 04/18] vmdk: Clean up descriptor file reading
9ae3a8
9ae3a8
RH-Author: Fam Zheng <famz@redhat.com>
9ae3a8
Message-id: <1455528511-9357-5-git-send-email-famz@redhat.com>
9ae3a8
Patchwork-id: 69170
9ae3a8
O-Subject: [RHEL-7.3 qemu-kvm PATCH 04/18] vmdk: Clean up descriptor file reading
9ae3a8
Bugzilla: 1299250
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1299250
9ae3a8
9ae3a8
Zeroing a buffer that will be filled right after is not necessary, and
9ae3a8
allocating a power of two + 1 is naughty.
9ae3a8
9ae3a8
Suggested-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Reviewed-by: Don Koch <dkoch@verizon.com>
9ae3a8
Reviewed-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: 1417649314-13704-4-git-send-email-famz@redhat.com
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 73b7bcad439e0edaced05049897090cc10d84b5b)
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/vmdk.c | 5 +++--
9ae3a8
 1 file changed, 3 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index 3f34abf..3dfbd41 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -559,8 +559,8 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
9ae3a8
         return NULL;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    size = MIN(size, 1 << 20);  /* avoid unbounded allocation */
9ae3a8
-    buf = g_malloc0(size + 1);
9ae3a8
+    size = MIN(size, (1 << 20) - 1);  /* avoid unbounded allocation */
9ae3a8
+    buf = g_malloc(size + 1);
9ae3a8
 
9ae3a8
     ret = bdrv_pread(file, desc_offset, buf, size);
9ae3a8
     if (ret < 0) {
9ae3a8
@@ -568,6 +568,7 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
9ae3a8
         g_free(buf);
9ae3a8
         return NULL;
9ae3a8
     }
9ae3a8
+    buf[ret] = 0;
9ae3a8
 
9ae3a8
     return buf;
9ae3a8
 }
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8