Differential Revision: https://phabricator.services.mozilla.com/D308888
347 lines
12 KiB
Diff
347 lines
12 KiB
Diff
diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c
|
|
--- a/expat/lib/xmlparse.c
|
|
+++ b/expat/lib/xmlparse.c
|
|
@@ -470,24 +470,36 @@ typedef unsigned long long XmlBigCount;
|
|
typedef struct accounting {
|
|
XmlBigCount countBytesDirect;
|
|
XmlBigCount countBytesIndirect;
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
unsigned long debugLevel;
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
float maximumAmplificationFactor; // >=1.0
|
|
unsigned long long activationThresholdBytes;
|
|
} ACCOUNTING;
|
|
|
|
typedef struct MALLOC_TRACKER {
|
|
XmlBigCount bytesAllocated;
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+# if 0
|
|
XmlBigCount peakBytesAllocated; // updated live only for debug level >=2
|
|
unsigned long debugLevel;
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
float maximumAmplificationFactor; // >=1.0
|
|
XmlBigCount activationThresholdBytes;
|
|
} MALLOC_TRACKER;
|
|
|
|
typedef struct entity_stats {
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
unsigned int countEverOpened;
|
|
unsigned int currentDepth;
|
|
unsigned int maximumDepthSeen;
|
|
unsigned long debugLevel;
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
} ENTITY_STATS;
|
|
#endif /* XML_GE == 1 */
|
|
|
|
@@ -649,18 +661,26 @@ static void parserInit(XML_Parser parser, const XML_Char *encodingName);
|
|
static float accountingGetCurrentAmplification(XML_Parser rootParser);
|
|
static void accountingReportStats(XML_Parser originParser, const char *epilog);
|
|
static void accountingOnAbort(XML_Parser originParser);
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static void accountingReportDiff(XML_Parser rootParser,
|
|
unsigned int levelsAwayFromRootParser,
|
|
const char *before, const char *after,
|
|
ptrdiff_t bytesMore, int source_line,
|
|
enum XML_Account account);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
static XML_Bool accountingDiffTolerated(XML_Parser originParser, int tok,
|
|
const char *before, const char *after,
|
|
int source_line,
|
|
enum XML_Account account);
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static void entityTrackingReportStats(XML_Parser parser, ENTITY *entity,
|
|
const char *action, int sourceLine);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
static void entityTrackingOnOpen(XML_Parser parser, ENTITY *entity,
|
|
int sourceLine);
|
|
static void entityTrackingOnClose(XML_Parser parser, ENTITY *entity,
|
|
@@ -670,8 +690,12 @@ static void entityTrackingOnClose(XML_Parser parser, ENTITY *entity,
|
|
static XML_Parser getRootParserOf(XML_Parser parser,
|
|
unsigned int *outLevelDiff);
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static unsigned long getDebugLevel(const char *variableName,
|
|
unsigned long defaultDebugLevel);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
static bool poolAppendChar(STRING_POOL *pool, XML_Char c);
|
|
|
|
@@ -855,6 +879,8 @@ struct XML_ParserStruct {
|
|
#endif
|
|
|
|
#if XML_GE == 1
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static void
|
|
expat_heap_stat(XML_Parser rootParser, char operator, XmlBigCount absDiff,
|
|
XmlBigCount newTotal, XmlBigCount peakTotal, int sourceLine) {
|
|
@@ -868,6 +894,8 @@ expat_heap_stat(XML_Parser rootParser, char operator, XmlBigCount absDiff,
|
|
(void *)rootParser, rootParser->m_accounting.countBytesDirect, operator,
|
|
absDiff, newTotal, peakTotal, (double)amplification, sourceLine);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
static bool
|
|
expat_heap_increase_tolerable(XML_Parser rootParser, XmlBigCount increase,
|
|
@@ -896,9 +924,13 @@ expat_heap_increase_tolerable(XML_Parser rootParser, XmlBigCount increase,
|
|
}
|
|
}
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
if (! tolerable && (rootParser->m_alloc_tracker.debugLevel >= 1)) {
|
|
expat_heap_stat(rootParser, '+', increase, newTotal, newTotal, sourceLine);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
return tolerable;
|
|
}
|
|
@@ -942,6 +974,8 @@ expat_malloc(XML_Parser parser, size_t size, int sourceLine) {
|
|
// Update accounting
|
|
rootParser->m_alloc_tracker.bytesAllocated += bytesToAllocate;
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
// Report as needed
|
|
if (rootParser->m_alloc_tracker.debugLevel >= 2) {
|
|
if (rootParser->m_alloc_tracker.bytesAllocated
|
|
@@ -953,6 +987,8 @@ expat_malloc(XML_Parser parser, size_t size, int sourceLine) {
|
|
rootParser->m_alloc_tracker.bytesAllocated,
|
|
rootParser->m_alloc_tracker.peakBytesAllocated, sourceLine);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
return (char *)mallocedPtr + sizeof(size_t) + EXPAT_MALLOC_PADDING;
|
|
}
|
|
@@ -982,12 +1018,16 @@ expat_free(XML_Parser parser, void *ptr, int sourceLine) {
|
|
assert(rootParser->m_alloc_tracker.bytesAllocated >= bytesAllocated);
|
|
rootParser->m_alloc_tracker.bytesAllocated -= bytesAllocated;
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
// Report as needed
|
|
if (rootParser->m_alloc_tracker.debugLevel >= 2) {
|
|
expat_heap_stat(rootParser, '-', bytesAllocated,
|
|
rootParser->m_alloc_tracker.bytesAllocated,
|
|
rootParser->m_alloc_tracker.peakBytesAllocated, sourceLine);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
// NOTE: This may be freeing rootParser, so freeing has to come last
|
|
parser->m_mem.free_fcn(mallocedPtr);
|
|
@@ -1052,6 +1092,8 @@ expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine) {
|
|
rootParser->m_alloc_tracker.bytesAllocated -= absDiff;
|
|
}
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
// Report as needed
|
|
if (rootParser->m_alloc_tracker.debugLevel >= 2) {
|
|
if (rootParser->m_alloc_tracker.bytesAllocated
|
|
@@ -1063,6 +1105,8 @@ expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine) {
|
|
rootParser->m_alloc_tracker.bytesAllocated,
|
|
rootParser->m_alloc_tracker.peakBytesAllocated, sourceLine);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
// Update in-block recorded size
|
|
*(size_t *)mallocedPtr = size;
|
|
@@ -1370,8 +1414,12 @@ parserCreate(const XML_Char *encodingName,
|
|
// Initialize .m_alloc_tracker
|
|
memset(&parser->m_alloc_tracker, 0, sizeof(MALLOC_TRACKER));
|
|
if (parentParser == NULL) {
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
parser->m_alloc_tracker.debugLevel
|
|
= getDebugLevel("EXPAT_MALLOC_DEBUG", 0u);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
parser->m_alloc_tracker.maximumAmplificationFactor
|
|
= EXPAT_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT;
|
|
parser->m_alloc_tracker.activationThresholdBytes
|
|
@@ -1391,6 +1439,8 @@ parserCreate(const XML_Char *encodingName,
|
|
assert(SIZE_MAX - rootParser->m_alloc_tracker.bytesAllocated >= increase);
|
|
rootParser->m_alloc_tracker.bytesAllocated += increase;
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
// Report on allocation
|
|
if (rootParser->m_alloc_tracker.debugLevel >= 2) {
|
|
if (rootParser->m_alloc_tracker.bytesAllocated
|
|
@@ -1403,6 +1453,8 @@ parserCreate(const XML_Char *encodingName,
|
|
rootParser->m_alloc_tracker.bytesAllocated,
|
|
rootParser->m_alloc_tracker.peakBytesAllocated, __LINE__);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
#else
|
|
parser->m_parentParser = NULL;
|
|
#endif // XML_GE == 1
|
|
@@ -1584,15 +1636,23 @@ parserInit(XML_Parser parser, const XML_Char *encodingName) {
|
|
|
|
#if XML_GE == 1
|
|
memset(&parser->m_accounting, 0, sizeof(ACCOUNTING));
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
parser->m_accounting.debugLevel = getDebugLevel("EXPAT_ACCOUNTING_DEBUG", 0u);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
parser->m_accounting.maximumAmplificationFactor
|
|
= EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT;
|
|
parser->m_accounting.activationThresholdBytes
|
|
= EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT;
|
|
|
|
memset(&parser->m_entity_stats, 0, sizeof(ENTITY_STATS));
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
parser->m_entity_stats.debugLevel = getDebugLevel("EXPAT_ENTITY_DEBUG", 0u);
|
|
#endif
|
|
+/* END MOZILLA CHANGE */
|
|
+#endif
|
|
}
|
|
|
|
/* moves list of bindings to m_freeBindingList */
|
|
@@ -8769,6 +8829,8 @@ accountingGetCurrentAmplification(XML_Parser rootParser) {
|
|
|
|
static void
|
|
accountingReportStats(XML_Parser originParser, const char *epilog) {
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
const XML_Parser rootParser = getRootParserOf(originParser, NULL);
|
|
assert(! rootParser->m_parentParser);
|
|
|
|
@@ -8784,6 +8846,8 @@ accountingReportStats(XML_Parser originParser, const char *epilog) {
|
|
(void *)rootParser, rootParser->m_accounting.countBytesDirect,
|
|
rootParser->m_accounting.countBytesIndirect,
|
|
(double)amplificationFactor, epilog);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
}
|
|
|
|
static void
|
|
@@ -8791,6 +8855,8 @@ accountingOnAbort(XML_Parser originParser) {
|
|
accountingReportStats(originParser, " ABORTING\n");
|
|
}
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static void
|
|
accountingReportDiff(XML_Parser rootParser,
|
|
unsigned int levelsAwayFromRootParser, const char *before,
|
|
@@ -8827,6 +8893,8 @@ accountingReportDiff(XML_Parser rootParser,
|
|
}
|
|
fprintf(stderr, "\"\n");
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
static XML_Bool
|
|
accountingDiffTolerated(XML_Parser originParser, int tok, const char *before,
|
|
@@ -8874,11 +8942,15 @@ accountingDiffTolerated(XML_Parser originParser, int tok, const char *before,
|
|
|| (amplificationFactor
|
|
<= rootParser->m_accounting.maximumAmplificationFactor);
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
if (rootParser->m_accounting.debugLevel >= 2u) {
|
|
accountingReportStats(rootParser, "");
|
|
accountingReportDiff(rootParser, levelsAwayFromRootParser, before, after,
|
|
bytesMore, source_line, account);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
return tolerated;
|
|
}
|
|
@@ -8897,6 +8969,8 @@ testingAccountingGetCountBytesIndirect(XML_Parser parser) {
|
|
return parser->m_accounting.countBytesIndirect;
|
|
}
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static void
|
|
entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity,
|
|
const char *action, int sourceLine) {
|
|
@@ -8930,9 +9004,13 @@ entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity,
|
|
ellipisOrEmpty, entity->is_param ? "%" : "&", entityName, action,
|
|
entity->textLen, sourceLine);
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
static void
|
|
entityTrackingOnOpen(XML_Parser originParser, ENTITY *entity, int sourceLine) {
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
const XML_Parser rootParser = getRootParserOf(originParser, NULL);
|
|
assert(! rootParser->m_parentParser);
|
|
|
|
@@ -8944,15 +9022,21 @@ entityTrackingOnOpen(XML_Parser originParser, ENTITY *entity, int sourceLine) {
|
|
}
|
|
|
|
entityTrackingReportStats(rootParser, entity, "OPEN ", sourceLine);
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
}
|
|
|
|
static void
|
|
entityTrackingOnClose(XML_Parser originParser, ENTITY *entity, int sourceLine) {
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
const XML_Parser rootParser = getRootParserOf(originParser, NULL);
|
|
assert(! rootParser->m_parentParser);
|
|
|
|
entityTrackingReportStats(rootParser, entity, "CLOSE", sourceLine);
|
|
rootParser->m_entity_stats.currentDepth--;
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
}
|
|
|
|
#endif /* XML_GE == 1 */
|
|
@@ -8974,6 +9058,8 @@ getRootParserOf(XML_Parser parser, unsigned int *outLevelDiff) {
|
|
|
|
#if XML_GE == 1
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
const char *
|
|
unsignedCharToPrintable(unsigned char c) {
|
|
switch (c) {
|
|
@@ -9497,9 +9583,13 @@ unsignedCharToPrintable(unsigned char c) {
|
|
assert(0); /* never gets here */
|
|
// LCOV_EXCL_STOP
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|
|
|
|
#endif /* XML_GE == 1 */
|
|
|
|
+/* BEGIN MOZILLA CHANGE (don't report debug information) */
|
|
+#if 0
|
|
static unsigned long
|
|
getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) {
|
|
const char *const valueOrNull = getenv(variableName);
|
|
@@ -9518,3 +9608,5 @@ getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) {
|
|
|
|
return debugLevel;
|
|
}
|
|
+#endif
|
|
+/* END MOZILLA CHANGE */
|