|
|
9119d9 |
From 0e8a4634d26eb2dbad659aa112f0b033ced576de Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <0e8a4634d26eb2dbad659aa112f0b033ced576de@dist-git>
|
|
|
9119d9 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
Date: Fri, 21 Nov 2014 15:04:05 +0100
|
|
|
9119d9 |
Subject: [PATCH] util: storage: Copy hosts of a storage file only if they
|
|
|
9119d9 |
exist
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1164528
|
|
|
9119d9 |
|
|
|
9119d9 |
If there are no hosts for a storage source virStorageSourceCopy and
|
|
|
9119d9 |
virStorageSourceNewFromBackingRelative would try to copy them anyways.
|
|
|
9119d9 |
As the success of virStorageNetHostDefCopy is determined by returning
|
|
|
9119d9 |
a pointer and malloc of 0 elements might return NULL according to the
|
|
|
9119d9 |
implementation, the result of the copy function may vary.
|
|
|
9119d9 |
|
|
|
9119d9 |
Fix this by copying the hosts array only if there are hosts defined.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit c264ea58e9a34b7202d8041687621dfa68ad8750)
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/util/virstoragefile.c | 19 +++++++++++++------
|
|
|
9119d9 |
1 file changed, 13 insertions(+), 6 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
9119d9 |
index d58f9ed..fa569d8 100644
|
|
|
9119d9 |
--- a/src/util/virstoragefile.c
|
|
|
9119d9 |
+++ b/src/util/virstoragefile.c
|
|
|
9119d9 |
@@ -1845,9 +1845,12 @@ virStorageSourceCopy(const virStorageSource *src,
|
|
|
9119d9 |
VIR_STRDUP(ret->compat, src->compat) < 0)
|
|
|
9119d9 |
goto error;
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (!(ret->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts)))
|
|
|
9119d9 |
- goto error;
|
|
|
9119d9 |
- ret->nhosts = src->nhosts;
|
|
|
9119d9 |
+ if (src->nhosts) {
|
|
|
9119d9 |
+ if (!(ret->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts)))
|
|
|
9119d9 |
+ goto error;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ ret->nhosts = src->nhosts;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
|
|
|
9119d9 |
if (src->srcpool &&
|
|
|
9119d9 |
!(ret->srcpool = virStorageSourcePoolDefCopy(src->srcpool)))
|
|
|
9119d9 |
@@ -2071,9 +2074,13 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
|
|
|
9119d9 |
|
|
|
9119d9 |
/* copy the host network part */
|
|
|
9119d9 |
ret->protocol = parent->protocol;
|
|
|
9119d9 |
- if (!(ret->hosts = virStorageNetHostDefCopy(parent->nhosts, parent->hosts)))
|
|
|
9119d9 |
- goto error;
|
|
|
9119d9 |
- ret->nhosts = parent->nhosts;
|
|
|
9119d9 |
+ if (parent->nhosts) {
|
|
|
9119d9 |
+ if (!(ret->hosts = virStorageNetHostDefCopy(parent->nhosts,
|
|
|
9119d9 |
+ parent->hosts)))
|
|
|
9119d9 |
+ goto error;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ ret->nhosts = parent->nhosts;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
|
|
|
9119d9 |
if (VIR_STRDUP(ret->volume, parent->volume) < 0)
|
|
|
9119d9 |
goto error;
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.3
|
|
|
9119d9 |
|