From: Nick Wellnhofer Date: Fri, 7 Aug 2020 19:54:27 +0000 (+0200) Subject: [CVE-2020-24977] Fix out-of-bounds read with 'xmllint --htmlout' X-Git-Tag: accepted/tizen/base/tool/20210223.010101^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1dd122f9bfe78e7074f08209b99b40c7b9a72314;p=platform%2Fupstream%2Flibxml2.git [CVE-2020-24977] Fix out-of-bounds read with 'xmllint --htmlout' Make sure that truncated UTF-8 sequences don't cause an out-of-bounds array access. Thanks to @SuhwanSong and the Agency for Defense Development (ADD) for the report. Fixes #178. Change-Id: Ibae2db998ba4c0f4ba1130869b4cec77a65d648e Signed-off-by: DongHun Kwak --- diff --git a/xmllint.c b/xmllint.c index 735d951..c071267 100644 --- a/xmllint.c +++ b/xmllint.c @@ -528,6 +528,12 @@ static void xmlHTMLEncodeSend(void) { char *result; + /* + * xmlEncodeEntitiesReentrant assumes valid UTF-8, but the buffer might + * end with a truncated UTF-8 sequence. This is a hack to at least avoid + * an out-of-bounds read. + */ + memset(&buffer[sizeof(buffer)-4], 0, 4); result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer); if (result) { xmlGenericError(xmlGenericErrorContext, "%s", result);