1 Star 0 Fork 71

wangyangdahai/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
libvirt-conf-vmx-check-for-OOM-after-calling-xmlBufferCreate.patch 3.75 KB
一键复制 编辑 原始数据 按行查看 历史
Hao_Wang 提交于 2020-09-22 17:11 . backport upstream patches
From 657c7f5d79fe43823ffb4d46e244bea15a65baf6 Mon Sep 17 00:00:00 2001
From: Laine Stump <laine@redhat.com>
Date: Thu, 18 Jun 2020 12:49:09 -0400
Subject: [PATCH 1/6] conf, vmx: check for OOM after calling xmlBufferCreate()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Although libvirt itself uses g_malloc0() and friends, which exit when
there isn't enouogh memory, libxml2 uses standard malloc(), which just
returns NULL on OOM - this means we must check for NULL on return from
any libxml2 functions that allocate memory.
xmlBufferCreate(), for example, might return NULL, and we don't always
check for it. This patch adds checks where it isn't already done.
(NB: Although libxml2 has a provision for changing behavior on OOM (by
calling xmlMemSetup() to change what functions are used to
allocating/freeing memory), we can't use that, since parts of libvirt
code end up in libvirt.so, which is linked and called directly by
applications that may themselves use libxml2 (and may have already set
their own alternate malloc()), e.g. drivers like esx which live totally
in the library rather than a separate process.)
cherry pick from: b7a92bce070fd57844a59bf8b1c30cb4ef4f3acd
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/conf/domain_conf.c | 6 +++++-
src/conf/network_conf.c | 6 +++++-
src/vmx/vmx.c | 11 +++++++----
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 914e03c..37c785a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29022,7 +29022,11 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
* Thankfully, libxml maps what looks like globals into
* thread-local uses, so we are thread-safe. */
xmlIndentTreeOutput = 1;
- xmlbuf = xmlBufferCreate();
+ if (!(xmlbuf = xmlBufferCreate())) {
+ virReportOOMError();
+ goto error;
+ }
+
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
virBufferGetIndent(buf) / 2, 1) < 0) {
xmlBufferFree(xmlbuf);
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 819b645..c379042 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -2478,7 +2478,11 @@ virNetworkDefFormatBuf(virBufferPtr buf,
* Thankfully, libxml maps what looks like globals into
* thread-local uses, so we are thread-safe. */
xmlIndentTreeOutput = 1;
- xmlbuf = xmlBufferCreate();
+ if (!(xmlbuf = xmlBufferCreate())) {
+ virReportOOMError();
+ return -1;
+ }
+
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
virBufferGetIndent(buf) / 2, 1) < 0) {
xmlBufferFree(xmlbuf);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index b1fd118..fbc8366 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -697,8 +697,8 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
{
char *result = NULL;
xmlCharEncodingHandlerPtr handler;
- xmlBufferPtr input;
- xmlBufferPtr utf8;
+ xmlBufferPtr input = NULL;
+ xmlBufferPtr utf8 = NULL;
handler = xmlFindCharEncodingHandler(encoding);
@@ -708,8 +708,11 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
return NULL;
}
- input = xmlBufferCreateStatic((char *)string, strlen(string));
- utf8 = xmlBufferCreate();
+ if (!(input = xmlBufferCreateStatic((char *)string, strlen(string))) ||
+ !(utf8 = xmlBufferCreate())) {
+ virReportOOMError();
+ goto cleanup;
+ }
if (xmlCharEncInFunc(handler, utf8, input) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangyangdahai/libvirt.git
git@gitee.com:wangyangdahai/libvirt.git
wangyangdahai
libvirt
libvirt
master

搜索帮助