~ubuntu-branches/ubuntu/wily/libxml2/wily-proposed

« back to all changes in this revision

Viewing changes to parser.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-10-16 15:28:40 UTC
  • Revision ID: package-import@ubuntu.com-20141016152840-epg6pn1cv4ga8hhz
Tags: 2.9.1+dfsg1-4ubuntu1
* SECURITY UPDATE: denial of service via entity expansion
  - debian/patches/CVE-2014-3660.patch: added additional tests to
    parser.c.
  - CVE-2014-3660

Show diffs side-by-side

added added

removed removed

Lines of Context:
130
130
        return (0);
131
131
    if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
132
132
        return (1);
 
133
 
 
134
    /*
 
135
     * This may look absurd but is needed to detect
 
136
     * entities problems
 
137
     */
 
138
    if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
 
139
        (ent->content != NULL) && (ent->checked == 0)) {
 
140
        unsigned long oldnbent = ctxt->nbentities;
 
141
        xmlChar *rep;
 
142
 
 
143
        ent->checked = 1;
 
144
 
 
145
        rep = xmlStringDecodeEntities(ctxt, ent->content,
 
146
                                  XML_SUBSTITUTE_REF, 0, 0, 0);
 
147
 
 
148
        ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
 
149
        if (rep != NULL) {
 
150
            if (xmlStrchr(rep, '<'))
 
151
                ent->checked |= 1;
 
152
            xmlFree(rep);
 
153
            rep = NULL;
 
154
        }
 
155
    }
133
156
    if (replacement != 0) {
134
157
        if (replacement < XML_MAX_TEXT_LENGTH)
135
158
            return(0);
189
212
            return (0);
190
213
    } else {
191
214
        /*
192
 
         * strange we got no data for checking just return
 
215
         * strange we got no data for checking
193
216
         */
194
 
        return (0);
 
217
        if (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&
 
218
             (ctxt->lastError.code != XML_WAR_UNDECLARED_ENTITY)) ||
 
219
            (ctxt->nbentities <= 10000))
 
220
            return (0);
195
221
    }
196
222
    xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
197
223
    return (1);
2584
2610
                                      name, NULL);
2585
2611
                    ctxt->valid = 0;
2586
2612
                }
 
2613
                xmlParserEntityCheck(ctxt, 0, NULL, 0);
2587
2614
            } else if (ctxt->input->free != deallocblankswrapper) {
2588
2615
                    input = xmlNewBlanksWrapperInputStream(ctxt, entity);
2589
2616
                    if (xmlPushInput(ctxt, input) < 0)
2754
2781
            if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||
2755
2782
                (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
2756
2783
                goto int_error;
 
2784
            xmlParserEntityCheck(ctxt, 0, ent, 0);
2757
2785
            if (ent != NULL)
2758
2786
                ctxt->nbentities += ent->checked / 2;
2759
2787
            if ((ent != NULL) &&
2805
2833
            ent = xmlParseStringPEReference(ctxt, &str);
2806
2834
            if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
2807
2835
                goto int_error;
 
2836
            xmlParserEntityCheck(ctxt, 0, ent, 0);
2808
2837
            if (ent != NULL)
2809
2838
                ctxt->nbentities += ent->checked / 2;
2810
2839
            if (ent != NULL) {
7307
7336
                   (ret != XML_WAR_UNDECLARED_ENTITY)) {
7308
7337
            xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7309
7338
                     "Entity '%s' failed to parse\n", ent->name);
 
7339
            xmlParserEntityCheck(ctxt, 0, ent, 0);
7310
7340
        } else if (list != NULL) {
7311
7341
            xmlFreeNodeList(list);
7312
7342
            list = NULL;
7413
7443
                /*
7414
7444
                 * We are copying here, make sure there is no abuse
7415
7445
                 */
7416
 
                ctxt->sizeentcopy += ent->length;
 
7446
                ctxt->sizeentcopy += ent->length + 5;
7417
7447
                if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7418
7448
                    return;
7419
7449
 
7461
7491
                /*
7462
7492
                 * We are copying here, make sure there is no abuse
7463
7493
                 */
7464
 
                ctxt->sizeentcopy += ent->length;
 
7494
                ctxt->sizeentcopy += ent->length + 5;
7465
7495
                if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7466
7496
                    return;
7467
7497
 
7647
7677
                ctxt->sax->reference(ctxt->userData, name);
7648
7678
            }
7649
7679
        }
 
7680
        xmlParserEntityCheck(ctxt, 0, ent, 0);
7650
7681
        ctxt->valid = 0;
7651
7682
    }
7652
7683
 
7840
7871
                          "Entity '%s' not defined\n",
7841
7872
                          name);
7842
7873
        }
 
7874
        xmlParserEntityCheck(ctxt, 0, ent, 0);
7843
7875
        /* TODO ? check regressions ctxt->valid = 0; */
7844
7876
    }
7845
7877
 
7999
8031
                          name, NULL);
8000
8032
            ctxt->valid = 0;
8001
8033
        }
 
8034
        xmlParserEntityCheck(ctxt, 0, NULL, 0);
8002
8035
    } else {
8003
8036
        /*
8004
8037
         * Internal checking in case the entity quest barfed
8238
8271
                          name, NULL);
8239
8272
            ctxt->valid = 0;
8240
8273
        }
 
8274
        xmlParserEntityCheck(ctxt, 0, NULL, 0);
8241
8275
    } else {
8242
8276
        /*
8243
8277
         * Internal checking in case the entity quest barfed