提交 c264ea58 编写于 作者: P Peter Krempa

util: storage: Copy hosts of a storage file only if they exist

If there are no hosts for a storage source virStorageSourceCopy and
virStorageSourceNewFromBackingRelative would try to copy them anyways.
As the success of virStorageNetHostDefCopy is determined by returning
a pointer and malloc of 0 elements might return NULL according to the
implementation, the result of the copy function may vary.

Fix this by copying the hosts array only if there are hosts defined.
上级 ceb3e595
...@@ -1851,9 +1851,12 @@ virStorageSourceCopy(const virStorageSource *src, ...@@ -1851,9 +1851,12 @@ virStorageSourceCopy(const virStorageSource *src,
VIR_STRDUP(ret->compat, src->compat) < 0) VIR_STRDUP(ret->compat, src->compat) < 0)
goto error; goto error;
if (!(ret->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts))) if (src->nhosts) {
goto error; if (!(ret->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts)))
ret->nhosts = src->nhosts; goto error;
ret->nhosts = src->nhosts;
}
if (src->srcpool && if (src->srcpool &&
!(ret->srcpool = virStorageSourcePoolDefCopy(src->srcpool))) !(ret->srcpool = virStorageSourcePoolDefCopy(src->srcpool)))
...@@ -2092,9 +2095,13 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, ...@@ -2092,9 +2095,13 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
/* copy the host network part */ /* copy the host network part */
ret->protocol = parent->protocol; ret->protocol = parent->protocol;
if (!(ret->hosts = virStorageNetHostDefCopy(parent->nhosts, parent->hosts))) if (parent->nhosts) {
goto error; if (!(ret->hosts = virStorageNetHostDefCopy(parent->nhosts,
ret->nhosts = parent->nhosts; parent->hosts)))
goto error;
ret->nhosts = parent->nhosts;
}
if (VIR_STRDUP(ret->volume, parent->volume) < 0) if (VIR_STRDUP(ret->volume, parent->volume) < 0)
goto error; goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册