153aa9179Sopenharmony_ciFrom 041789d9ec5a0f592e200bcb7313d88ff14707e4 Mon Sep 17 00:00:00 2001 253aa9179Sopenharmony_ciFrom: Nick Wellnhofer <wellnhofer@aevum.de> 353aa9179Sopenharmony_ciDate: Thu, 16 Feb 2023 15:02:08 +0100 453aa9179Sopenharmony_ciSubject: [PATCH] malloc-fail: Fix null deref in htmlnamePush 553aa9179Sopenharmony_ci 653aa9179Sopenharmony_ciFound with libFuzzer, see #344. 753aa9179Sopenharmony_ci 853aa9179Sopenharmony_ciReference:https://github.com/GNOME/libxml2/commit/041789d9ec5a0f592e200bcb7313d88ff14707e4 953aa9179Sopenharmony_ciConflict:NA 1053aa9179Sopenharmony_ci--- 1153aa9179Sopenharmony_ci HTMLparser.c | 18 ++++++++++-------- 1253aa9179Sopenharmony_ci 1 file changed, 10 insertions(+), 8 deletions(-) 1353aa9179Sopenharmony_ci 1453aa9179Sopenharmony_cidiff --git a/HTMLparser.c b/HTMLparser.c 1553aa9179Sopenharmony_ciindex ca551d9..e02a142 100644 1653aa9179Sopenharmony_ci--- a/HTMLparser.c 1753aa9179Sopenharmony_ci+++ b/HTMLparser.c 1853aa9179Sopenharmony_ci@@ -161,7 +161,7 @@ htmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error, 1953aa9179Sopenharmony_ci * 2053aa9179Sopenharmony_ci * Pushes a new element name on top of the name stack 2153aa9179Sopenharmony_ci * 2253aa9179Sopenharmony_ci- * Returns 0 in case of error, the index in the stack otherwise 2353aa9179Sopenharmony_ci+ * Returns -1 in case of error, the index in the stack otherwise 2453aa9179Sopenharmony_ci */ 2553aa9179Sopenharmony_ci static int 2653aa9179Sopenharmony_ci htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value) 2753aa9179Sopenharmony_ci@@ -171,15 +171,17 @@ htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value) 2853aa9179Sopenharmony_ci if ((ctxt->html < 10) && (xmlStrEqual(value, BAD_CAST "body"))) 2953aa9179Sopenharmony_ci ctxt->html = 10; 3053aa9179Sopenharmony_ci if (ctxt->nameNr >= ctxt->nameMax) { 3153aa9179Sopenharmony_ci- ctxt->nameMax *= 2; 3253aa9179Sopenharmony_ci- ctxt->nameTab = (const xmlChar * *) 3353aa9179Sopenharmony_ci- xmlRealloc((xmlChar * *)ctxt->nameTab, 3453aa9179Sopenharmony_ci- ctxt->nameMax * 3553aa9179Sopenharmony_ci- sizeof(ctxt->nameTab[0])); 3653aa9179Sopenharmony_ci- if (ctxt->nameTab == NULL) { 3753aa9179Sopenharmony_ci+ size_t newSize = ctxt->nameMax * 2; 3853aa9179Sopenharmony_ci+ const xmlChar **tmp; 3953aa9179Sopenharmony_ci+ 4053aa9179Sopenharmony_ci+ tmp = xmlRealloc((xmlChar **) ctxt->nameTab, 4153aa9179Sopenharmony_ci+ newSize * sizeof(ctxt->nameTab[0])); 4253aa9179Sopenharmony_ci+ if (tmp == NULL) { 4353aa9179Sopenharmony_ci htmlErrMemory(ctxt, NULL); 4453aa9179Sopenharmony_ci- return (0); 4553aa9179Sopenharmony_ci+ return (-1); 4653aa9179Sopenharmony_ci } 4753aa9179Sopenharmony_ci+ ctxt->nameTab = tmp; 4853aa9179Sopenharmony_ci+ ctxt->nameMax = newSize; 4953aa9179Sopenharmony_ci } 5053aa9179Sopenharmony_ci ctxt->nameTab[ctxt->nameNr] = value; 5153aa9179Sopenharmony_ci ctxt->name = value; 5253aa9179Sopenharmony_ci-- 5353aa9179Sopenharmony_ci2.27.0 5453aa9179Sopenharmony_ci 55