1
From be2a7edaf289c5da74a4f9ed3a0b6c733e775230 Mon Sep 17 00:00:00 2001
2
From: Daniel Veillard <veillard@redhat.com>
3
Date: Thu, 16 Oct 2014 13:59:47 +0800
4
Subject: Fix for CVE-2014-3660
6
Issues related to the billion laugh entity expansion which happened to
7
escape the initial set of fixes
9
Index: libxml2-2.9.1+dfsg1/parser.c
10
===================================================================
11
--- libxml2-2.9.1+dfsg1.orig/parser.c 2014-10-16 15:30:40.885274343 -0400
12
+++ libxml2-2.9.1+dfsg1/parser.c 2014-10-16 15:30:40.881274311 -0400
15
if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
19
+ * This may look absurd but is needed to detect
22
+ if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
23
+ (ent->content != NULL) && (ent->checked == 0)) {
24
+ unsigned long oldnbent = ctxt->nbentities;
29
+ rep = xmlStringDecodeEntities(ctxt, ent->content,
30
+ XML_SUBSTITUTE_REF, 0, 0, 0);
32
+ ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
34
+ if (xmlStrchr(rep, '<'))
40
if (replacement != 0) {
41
if (replacement < XML_MAX_TEXT_LENGTH)
47
- * strange we got no data for checking just return
48
+ * strange we got no data for checking
51
+ if (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&
52
+ (ctxt->lastError.code != XML_WAR_UNDECLARED_ENTITY)) ||
53
+ (ctxt->nbentities <= 10000))
56
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
62
+ xmlParserEntityCheck(ctxt, 0, NULL, 0);
63
} else if (ctxt->input->free != deallocblankswrapper) {
64
input = xmlNewBlanksWrapperInputStream(ctxt, entity);
65
if (xmlPushInput(ctxt, input) < 0)
67
if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||
68
(ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
70
+ xmlParserEntityCheck(ctxt, 0, ent, 0);
72
ctxt->nbentities += ent->checked / 2;
75
ent = xmlParseStringPEReference(ctxt, &str);
76
if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
78
+ xmlParserEntityCheck(ctxt, 0, ent, 0);
80
ctxt->nbentities += ent->checked / 2;
83
(ret != XML_WAR_UNDECLARED_ENTITY)) {
84
xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
85
"Entity '%s' failed to parse\n", ent->name);
86
+ xmlParserEntityCheck(ctxt, 0, ent, 0);
87
} else if (list != NULL) {
88
xmlFreeNodeList(list);
92
* We are copying here, make sure there is no abuse
94
- ctxt->sizeentcopy += ent->length;
95
+ ctxt->sizeentcopy += ent->length + 5;
96
if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
101
* We are copying here, make sure there is no abuse
103
- ctxt->sizeentcopy += ent->length;
104
+ ctxt->sizeentcopy += ent->length + 5;
105
if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
108
@@ -7647,6 +7677,7 @@
109
ctxt->sax->reference(ctxt->userData, name);
112
+ xmlParserEntityCheck(ctxt, 0, ent, 0);
116
@@ -7840,6 +7871,7 @@
117
"Entity '%s' not defined\n",
120
+ xmlParserEntityCheck(ctxt, 0, ent, 0);
121
/* TODO ? check regressions ctxt->valid = 0; */
124
@@ -7999,6 +8031,7 @@
128
+ xmlParserEntityCheck(ctxt, 0, NULL, 0);
131
* Internal checking in case the entity quest barfed
132
@@ -8238,6 +8271,7 @@
136
+ xmlParserEntityCheck(ctxt, 0, NULL, 0);
139
* Internal checking in case the entity quest barfed