cryptospore / rpms / qemu-kvm

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