|
|
9ae3a8 |
From a767838caf6c761d714a9466d008f8dddaf1a162 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 15 Feb 2016 09:28:22 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 09/18] block: vmdk - move string allocations from stack to the
|
|
|
9ae3a8 |
heap
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1455528511-9357-10-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 69175
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.3 qemu-kvm PATCH 09/18] block: vmdk - move string allocations from stack to the heap
|
|
|
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 |
From: Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1299250
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Functions 'vmdk_parse_extents' and 'vmdk_create' allocate several
|
|
|
9ae3a8 |
PATH_MAX sized arrays on the stack. Make these dynamically allocated.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit fe2065629a9c256f836770ca54449ae77b22d188)
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vmdk.c | 40 ++++++++++++++++++++++++----------------
|
|
|
9ae3a8 |
1 file changed, 24 insertions(+), 16 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vmdk.c b/block/vmdk.c
|
|
|
9ae3a8 |
index 3351782..45ecf02 100644
|
|
|
9ae3a8 |
--- a/block/vmdk.c
|
|
|
9ae3a8 |
+++ b/block/vmdk.c
|
|
|
9ae3a8 |
@@ -795,12 +795,11 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
const char *p = desc;
|
|
|
9ae3a8 |
int64_t sectors = 0;
|
|
|
9ae3a8 |
int64_t flat_offset;
|
|
|
9ae3a8 |
- char extent_path[PATH_MAX];
|
|
|
9ae3a8 |
+ char *extent_path;
|
|
|
9ae3a8 |
BlockDriverState *extent_file;
|
|
|
9ae3a8 |
BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
VmdkExtent *extent;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
while (*p) {
|
|
|
9ae3a8 |
/* parse extent line in one of below formats:
|
|
|
9ae3a8 |
*
|
|
|
9ae3a8 |
@@ -838,10 +837,13 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
goto next_line;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ extent_path = g_malloc0(PATH_MAX);
|
|
|
9ae3a8 |
path_combine(extent_path, sizeof(extent_path),
|
|
|
9ae3a8 |
desc_file_path, fname);
|
|
|
9ae3a8 |
+ extent_file = NULL;
|
|
|
9ae3a8 |
ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,
|
|
|
9ae3a8 |
errp);
|
|
|
9ae3a8 |
+ g_free(extent_path);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1790,10 +1792,15 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
int ret = 0;
|
|
|
9ae3a8 |
bool flat, split, compress;
|
|
|
9ae3a8 |
GString *ext_desc_lines;
|
|
|
9ae3a8 |
- char path[PATH_MAX], prefix[PATH_MAX], postfix[PATH_MAX];
|
|
|
9ae3a8 |
+ char *path = g_malloc0(PATH_MAX);
|
|
|
9ae3a8 |
+ char *prefix = g_malloc0(PATH_MAX);
|
|
|
9ae3a8 |
+ char *postfix = g_malloc0(PATH_MAX);
|
|
|
9ae3a8 |
+ char *desc_line = g_malloc0(BUF_SIZE);
|
|
|
9ae3a8 |
+ char *ext_filename = g_malloc0(PATH_MAX);
|
|
|
9ae3a8 |
+ char *desc_filename = g_malloc0(PATH_MAX);
|
|
|
9ae3a8 |
const int64_t split_size = 0x80000000; /* VMDK has constant split size */
|
|
|
9ae3a8 |
const char *desc_extent_line;
|
|
|
9ae3a8 |
- char parent_desc_line[BUF_SIZE] = "";
|
|
|
9ae3a8 |
+ char *parent_desc_line = g_malloc0(BUF_SIZE);
|
|
|
9ae3a8 |
uint32_t parent_cid = 0xffffffff;
|
|
|
9ae3a8 |
uint32_t number_heads = 16;
|
|
|
9ae3a8 |
bool zeroed_grain = false;
|
|
|
9ae3a8 |
@@ -1902,33 +1909,27 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
parent_cid = vmdk_read_cid(bs, 0);
|
|
|
9ae3a8 |
bdrv_unref(bs);
|
|
|
9ae3a8 |
- snprintf(parent_desc_line, sizeof(parent_desc_line),
|
|
|
9ae3a8 |
+ snprintf(parent_desc_line, BUF_SIZE,
|
|
|
9ae3a8 |
"parentFileNameHint=\"%s\"", backing_file);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Create extents */
|
|
|
9ae3a8 |
filesize = total_size;
|
|
|
9ae3a8 |
while (filesize > 0) {
|
|
|
9ae3a8 |
- char desc_line[BUF_SIZE];
|
|
|
9ae3a8 |
- char ext_filename[PATH_MAX];
|
|
|
9ae3a8 |
- char desc_filename[PATH_MAX];
|
|
|
9ae3a8 |
int64_t size = filesize;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (split && size > split_size) {
|
|
|
9ae3a8 |
size = split_size;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (split) {
|
|
|
9ae3a8 |
- snprintf(desc_filename, sizeof(desc_filename), "%s-%c%03d%s",
|
|
|
9ae3a8 |
+ snprintf(desc_filename, PATH_MAX, "%s-%c%03d%s",
|
|
|
9ae3a8 |
prefix, flat ? 'f' : 's', ++idx, postfix);
|
|
|
9ae3a8 |
} else if (flat) {
|
|
|
9ae3a8 |
- snprintf(desc_filename, sizeof(desc_filename), "%s-flat%s",
|
|
|
9ae3a8 |
- prefix, postfix);
|
|
|
9ae3a8 |
+ snprintf(desc_filename, PATH_MAX, "%s-flat%s", prefix, postfix);
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- snprintf(desc_filename, sizeof(desc_filename), "%s%s",
|
|
|
9ae3a8 |
- prefix, postfix);
|
|
|
9ae3a8 |
+ snprintf(desc_filename, PATH_MAX, "%s%s", prefix, postfix);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- snprintf(ext_filename, sizeof(ext_filename), "%s%s",
|
|
|
9ae3a8 |
- path, desc_filename);
|
|
|
9ae3a8 |
+ snprintf(ext_filename, PATH_MAX, "%s%s", path, desc_filename);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (vmdk_create_extent(ext_filename, size,
|
|
|
9ae3a8 |
flat, compress, zeroed_grain, errp)) {
|
|
|
9ae3a8 |
@@ -1938,7 +1939,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
filesize -= size;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Format description line */
|
|
|
9ae3a8 |
- snprintf(desc_line, sizeof(desc_line),
|
|
|
9ae3a8 |
+ snprintf(desc_line, BUF_SIZE,
|
|
|
9ae3a8 |
desc_extent_line, size / BDRV_SECTOR_SIZE, desc_filename);
|
|
|
9ae3a8 |
g_string_append(ext_desc_lines, desc_line);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1988,6 +1989,13 @@ exit:
|
|
|
9ae3a8 |
bdrv_unref(new_bs);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
g_free(desc);
|
|
|
9ae3a8 |
+ g_free(path);
|
|
|
9ae3a8 |
+ g_free(prefix);
|
|
|
9ae3a8 |
+ g_free(postfix);
|
|
|
9ae3a8 |
+ g_free(desc_line);
|
|
|
9ae3a8 |
+ g_free(ext_filename);
|
|
|
9ae3a8 |
+ g_free(desc_filename);
|
|
|
9ae3a8 |
+ g_free(parent_desc_line);
|
|
|
9ae3a8 |
g_string_free(ext_desc_lines, true);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|