|
1 |
| -/* fcb1a62fefa945567301146eb98e3ad3413e823a41c4378e84e8b6b6f308d824 (2.4.7+) |
| 1 | +/* 5ab094ffadd6edfc94c3eee53af44a86951f9f1f0933ada3114bbce2bfb02c99 (2.5.0+) |
2 | 2 | __ __ _
|
3 | 3 | ___\ \/ /_ __ __ _| |_
|
4 | 4 | / _ \\ /| '_ \ / _` | __|
|
|
35 | 35 | Copyright (c) 2021 Dong-hee Na <[email protected]>
|
36 | 36 | Copyright (c) 2022 Samanta Navarro <[email protected]>
|
37 | 37 | Copyright (c) 2022 Jeffrey Walton <[email protected]>
|
| 38 | + Copyright (c) 2022 Jann Horn <[email protected]> |
38 | 39 | Licensed under the MIT license:
|
39 | 40 |
|
40 | 41 | Permission is hereby granted, free of charge, to any person obtaining
|
@@ -1088,6 +1089,14 @@ parserCreate(const XML_Char *encodingName,
|
1088 | 1089 | parserInit(parser, encodingName);
|
1089 | 1090 |
|
1090 | 1091 | if (encodingName && ! parser->m_protocolEncodingName) {
|
| 1092 | + if (dtd) { |
| 1093 | + // We need to stop the upcoming call to XML_ParserFree from happily |
| 1094 | + // destroying parser->m_dtd because the DTD is shared with the parent |
| 1095 | + // parser and the only guard that keeps XML_ParserFree from destroying |
| 1096 | + // parser->m_dtd is parser->m_isParamEntity but it will be set to |
| 1097 | + // XML_TRUE only later in XML_ExternalEntityParserCreate (or not at all). |
| 1098 | + parser->m_dtd = NULL; |
| 1099 | + } |
1091 | 1100 | XML_ParserFree(parser);
|
1092 | 1101 | return NULL;
|
1093 | 1102 | }
|
@@ -3031,16 +3040,16 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,
|
3031 | 3040 | int len;
|
3032 | 3041 | const char *rawName;
|
3033 | 3042 | TAG *tag = parser->m_tagStack;
|
3034 |
| - parser->m_tagStack = tag->parent; |
3035 |
| - tag->parent = parser->m_freeTagList; |
3036 |
| - parser->m_freeTagList = tag; |
3037 | 3043 | rawName = s + enc->minBytesPerChar * 2;
|
3038 | 3044 | len = XmlNameLength(enc, rawName);
|
3039 | 3045 | if (len != tag->rawNameLength
|
3040 | 3046 | || memcmp(tag->rawName, rawName, len) != 0) {
|
3041 | 3047 | *eventPP = rawName;
|
3042 | 3048 | return XML_ERROR_TAG_MISMATCH;
|
3043 | 3049 | }
|
| 3050 | + parser->m_tagStack = tag->parent; |
| 3051 | + tag->parent = parser->m_freeTagList; |
| 3052 | + parser->m_freeTagList = tag; |
3044 | 3053 | --parser->m_tagLevel;
|
3045 | 3054 | if (parser->m_endElementHandler) {
|
3046 | 3055 | const XML_Char *localPart;
|
@@ -4995,10 +5004,10 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
|
4995 | 5004 | parser->m_handlerArg, parser->m_declElementType->name,
|
4996 | 5005 | parser->m_declAttributeId->name, parser->m_declAttributeType, 0,
|
4997 | 5006 | role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE);
|
4998 |
| - poolClear(&parser->m_tempPool); |
4999 | 5007 | handleDefault = XML_FALSE;
|
5000 | 5008 | }
|
5001 | 5009 | }
|
| 5010 | + poolClear(&parser->m_tempPool); |
5002 | 5011 | break;
|
5003 | 5012 | case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE:
|
5004 | 5013 | case XML_ROLE_FIXED_ATTRIBUTE_VALUE:
|
@@ -5406,7 +5415,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
|
5406 | 5415 | *
|
5407 | 5416 | * If 'standalone' is false, the DTD must have no
|
5408 | 5417 | * parameter entities or we wouldn't have passed the outer
|
5409 |
| - * 'if' statement. That measn the only entity in the hash |
| 5418 | + * 'if' statement. That means the only entity in the hash |
5410 | 5419 | * table is the external subset name "#" which cannot be
|
5411 | 5420 | * given as a parameter entity name in XML syntax, so the
|
5412 | 5421 | * lookup must have returned NULL and we don't even reach
|
@@ -5818,19 +5827,27 @@ internalEntityProcessor(XML_Parser parser, const char *s, const char *end,
|
5818 | 5827 |
|
5819 | 5828 | if (result != XML_ERROR_NONE)
|
5820 | 5829 | return result;
|
5821 |
| - else if (textEnd != next |
5822 |
| - && parser->m_parsingStatus.parsing == XML_SUSPENDED) { |
| 5830 | + |
| 5831 | + if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) { |
5823 | 5832 | entity->processed = (int)(next - (const char *)entity->textPtr);
|
5824 | 5833 | return result;
|
5825 |
| - } else { |
| 5834 | + } |
| 5835 | + |
5826 | 5836 | #ifdef XML_DTD
|
5827 |
| - entityTrackingOnClose(parser, entity, __LINE__); |
| 5837 | + entityTrackingOnClose(parser, entity, __LINE__); |
5828 | 5838 | #endif
|
5829 |
| - entity->open = XML_FALSE; |
5830 |
| - parser->m_openInternalEntities = openEntity->next; |
5831 |
| - /* put openEntity back in list of free instances */ |
5832 |
| - openEntity->next = parser->m_freeInternalEntities; |
5833 |
| - parser->m_freeInternalEntities = openEntity; |
| 5839 | + entity->open = XML_FALSE; |
| 5840 | + parser->m_openInternalEntities = openEntity->next; |
| 5841 | + /* put openEntity back in list of free instances */ |
| 5842 | + openEntity->next = parser->m_freeInternalEntities; |
| 5843 | + parser->m_freeInternalEntities = openEntity; |
| 5844 | + |
| 5845 | + // If there are more open entities we want to stop right here and have the |
| 5846 | + // upcoming call to XML_ResumeParser continue with entity content, or it would |
| 5847 | + // be ignored altogether. |
| 5848 | + if (parser->m_openInternalEntities != NULL |
| 5849 | + && parser->m_parsingStatus.parsing == XML_SUSPENDED) { |
| 5850 | + return XML_ERROR_NONE; |
5834 | 5851 | }
|
5835 | 5852 |
|
5836 | 5853 | #ifdef XML_DTD
|
|
0 commit comments