1 Star 0 Fork 40

HuBin95 / libxml2

forked from src-openEuler / libxml2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Only-warn-on-invalid-redeclarations-of-predefined-en.patch 3.66 KB
一键复制 编辑 原始数据 按行查看 历史
谢志鹏 提交于 2022-11-29 15:28 . backport upstream patches
From ce0871e15cdb68e505ccd9d9c96ff8455ed936ab Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Sun, 20 Feb 2022 16:44:41 +0100
Subject: [PATCH 1/3] Only warn on invalid redeclarations of predefined
entities
Downgrade the error message to a warning since the error was ignored,
anyway. Also print the name of redeclared entity. For a proper fix that
also shows filename and line number of the invalid redeclaration, we'd
have to
- pass the parser context to the entity functions somehow, or
- make these functions return distinct error codes.
Partial fix for #308.
---
entities.c | 21 +++++++++++++++++++--
result/errors/ent_redecl.xml | 3 +++
result/errors/ent_redecl.xml.ent | 1 +
result/errors/ent_redecl.xml.err | 1 +
result/errors/ent_redecl.xml.str | 1 +
test/errors/ent_redecl.xml | 4 ++++
6 files changed, 29 insertions(+), 2 deletions(-)
create mode 100644 result/errors/ent_redecl.xml
create mode 100644 result/errors/ent_redecl.xml.ent
create mode 100644 result/errors/ent_redecl.xml.err
create mode 100644 result/errors/ent_redecl.xml.str
create mode 100644 test/errors/ent_redecl.xml
diff --git a/entities.c b/entities.c
index 1a8f86f0..a27209d1 100644
--- a/entities.c
+++ b/entities.c
@@ -94,6 +94,23 @@ xmlEntitiesErr(xmlParserErrors code, const char *msg)
__xmlSimpleError(XML_FROM_TREE, code, NULL, msg, NULL);
}
+/**
+ * xmlEntitiesWarn:
+ * @code: the error code
+ * @msg: the message
+ *
+ * Handle an out of memory condition
+ */
+static void LIBXML_ATTR_FORMAT(2,0)
+xmlEntitiesWarn(xmlParserErrors code, const char *msg, const xmlChar *str1)
+{
+ __xmlRaiseError(NULL, NULL, NULL,
+ NULL, NULL, XML_FROM_TREE, code,
+ XML_ERR_WARNING, NULL, 0,
+ (const char *)str1, NULL, NULL, 0, 0,
+ msg, (const char *)str1, NULL);
+}
+
/*
* xmlFreeEntity : clean-up an entity record.
*/
@@ -255,9 +272,9 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
}
}
if (!valid) {
- xmlEntitiesErr(XML_ERR_ENTITY_PROCESSING,
+ xmlEntitiesWarn(XML_ERR_ENTITY_PROCESSING,
"xmlAddEntity: invalid redeclaration of predefined"
- " entity");
+ " entity '%s'", name);
return(NULL);
}
}
diff --git a/result/errors/ent_redecl.xml b/result/errors/ent_redecl.xml
new file mode 100644
index 00000000..04216b65
--- /dev/null
+++ b/result/errors/ent_redecl.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<!DOCTYPE doc>
+<doc/>
diff --git a/result/errors/ent_redecl.xml.ent b/result/errors/ent_redecl.xml.ent
new file mode 100644
index 00000000..31908b05
--- /dev/null
+++ b/result/errors/ent_redecl.xml.ent
@@ -0,0 +1 @@
+warning : xmlAddEntity: invalid redeclaration of predefined entity 'lt'
diff --git a/result/errors/ent_redecl.xml.err b/result/errors/ent_redecl.xml.err
new file mode 100644
index 00000000..31908b05
--- /dev/null
+++ b/result/errors/ent_redecl.xml.err
@@ -0,0 +1 @@
+warning : xmlAddEntity: invalid redeclaration of predefined entity 'lt'
diff --git a/result/errors/ent_redecl.xml.str b/result/errors/ent_redecl.xml.str
new file mode 100644
index 00000000..31908b05
--- /dev/null
+++ b/result/errors/ent_redecl.xml.str
@@ -0,0 +1 @@
+warning : xmlAddEntity: invalid redeclaration of predefined entity 'lt'
diff --git a/test/errors/ent_redecl.xml b/test/errors/ent_redecl.xml
new file mode 100644
index 00000000..e446681b
--- /dev/null
+++ b/test/errors/ent_redecl.xml
@@ -0,0 +1,4 @@
+<!DOCTYPE doc [
+ <!ENTITY lt '<'>
+]>
+<doc/>
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hubin95/libxml2.git
git@gitee.com:hubin95/libxml2.git
hubin95
libxml2
libxml2
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891