From 5db5a704eb6b030e6bebec9d358d739f1eb24fed Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 9 Aug 2023 18:39:14 +0200 Subject: [PATCH] html: Fix UAF in htmlCurrentChar Short-lived regression found by OSS-Fuzz. --- HTMLparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HTMLparser.c b/HTMLparser.c index ba3eb16d..c2d05ba4 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -445,7 +445,6 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) { xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1); } else { handler = xmlFindCharEncodingHandler((const char *) guess); - xmlFree(guess); if (handler != NULL) { /* * Don't use UTF-8 encoder which isn't required and @@ -457,6 +456,7 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) { htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING, "Unsupported encoding %s", guess, NULL); } + xmlFree(guess); } ctxt->input->flags |= XML_INPUT_HAS_ENCODING; }