1 Star 0 Fork 52

冉召宇/third_party_libxml2_1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
backport-malloc-fail-Fix-null-deref-after-xmlSchemaItemList-A.patch 2.68 KB
一键复制 编辑 原始数据 按行查看 历史
冉召宇 提交于 2024-04-25 19:13 +08:00 . libxml2切openEuler7.0
From 767ae50bc9e94a35bfede3af291cf0060893db0f Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Sun, 5 Mar 2023 14:11:24 +0100
Subject: [PATCH] malloc-fail: Fix null deref after
xmlSchemaItemList{Add,Insert}
Found with libFuzzer, see #344.
Reference:https://github.com/GNOME/libxml2/commit/767ae50bc9e94a35bfede3af291cf0060893db0f
Conflict:NA
---
xmlschemas.c | 44 ++++++++++++++++----------------------------
1 file changed, 16 insertions(+), 28 deletions(-)
diff --git a/xmlschemas.c b/xmlschemas.c
index 46cbe0f..d2f8bf1 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -3417,23 +3417,17 @@ xmlSchemaItemListClear(xmlSchemaItemListPtr list)
static int
xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item)
{
- if (list->items == NULL) {
- list->items = (void **) xmlMalloc(
- 20 * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
- return(-1);
- }
- list->sizeItems = 20;
- } else if (list->sizeItems <= list->nbItems) {
- list->sizeItems *= 2;
- list->items = (void **) xmlRealloc(list->items,
- list->sizeItems * sizeof(void *));
- if (list->items == NULL) {
+ if (list->sizeItems <= list->nbItems) {
+ void **tmp;
+ size_t newSize = list->sizeItems == 0 ? 20 : list->sizeItems * 2;
+
+ tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *));
+ if (tmp == NULL) {
xmlSchemaPErrMemory(NULL, "growing item list", NULL);
- list->sizeItems = 0;
return(-1);
}
+ list->items = tmp;
+ list->sizeItems = newSize;
}
list->items[list->nbItems++] = item;
return(0);
@@ -3474,23 +3468,17 @@ xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
static int
xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
{
- if (list->items == NULL) {
- list->items = (void **) xmlMalloc(
- 20 * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
- return(-1);
- }
- list->sizeItems = 20;
- } else if (list->sizeItems <= list->nbItems) {
- list->sizeItems *= 2;
- list->items = (void **) xmlRealloc(list->items,
- list->sizeItems * sizeof(void *));
- if (list->items == NULL) {
+ if (list->sizeItems <= list->nbItems) {
+ void **tmp;
+ size_t newSize = list->sizeItems == 0 ? 20 : list->sizeItems * 2;
+
+ tmp = (void **) xmlRealloc(list->items, newSize * sizeof(void *));
+ if (tmp == NULL) {
xmlSchemaPErrMemory(NULL, "growing item list", NULL);
- list->sizeItems = 0;
return(-1);
}
+ list->items = tmp;
+ list->sizeItems = newSize;
}
/*
* Just append if the index is greater/equal than the item count.
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ran-zhao-yu/third_party_libxml2_1.git
git@gitee.com:ran-zhao-yu/third_party_libxml2_1.git
ran-zhao-yu
third_party_libxml2_1
third_party_libxml2_1
master

搜索帮助