加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
backport-malloc-fail-Fix-reallocation-in-xmlXIncludeNewRef.patch 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
冉召宇 提交于 2024-04-25 19:13 . libxml2切openEuler7.0
From a3749551e65a8caf146ea2bccf610e718d90bde0 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Fri, 3 Feb 2023 14:00:13 +0100
Subject: [PATCH] malloc-fail: Fix reallocation in xmlXIncludeNewRef
Avoid null deref.
Found with libFuzzer, see #344.
Reference:https://github.com/GNOME/libxml2/commit/a3749551e65a8caf146ea2bccf610e718d90bde0
Conflict:xinclude.c
---
xinclude.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/xinclude.c b/xinclude.c
index 60a0d7b..cc486f5 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -257,14 +257,18 @@ xmlXIncludeNewRef(xmlXIncludeCtxtPtr ctxt, const xmlChar *URI,
}
}
if (ctxt->incNr >= ctxt->incMax) {
- ctxt->incMax *= 2;
- ctxt->incTab = (xmlXIncludeRefPtr *) xmlRealloc(ctxt->incTab,
- ctxt->incMax * sizeof(ctxt->incTab[0]));
- if (ctxt->incTab == NULL) {
+ xmlXIncludeRefPtr *tmp;
+ size_t newSize = ctxt->incMax * 2;
+
+ tmp = (xmlXIncludeRefPtr *) xmlRealloc(ctxt->incTab,
+ newSize * sizeof(ctxt->incTab[0]));
+ if (tmp == NULL) {
xmlXIncludeErrMemory(ctxt, ref, "growing XInclude context");
xmlXIncludeFreeRef(ret);
return(NULL);
}
+ ctxt->incTab = tmp;
+ ctxt->incMax *= 2;
}
ctxt->incTab[ctxt->incNr++] = ret;
return(ret);
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化