bcf091
From 0e1a49c8907645d2e155f0d89d4d9895ac5112b5 Mon Sep 17 00:00:00 2001
bcf091
From: Zhipeng Xie <xiezhipeng1@huawei.com>
bcf091
Date: Thu, 12 Dec 2019 17:30:55 +0800
bcf091
Subject: [PATCH] Fix infinite loop in xmlStringLenDecodeEntities
bcf091
bcf091
When ctxt->instate == XML_PARSER_EOF,xmlParseStringEntityRef
bcf091
return NULL which cause a infinite loop in xmlStringLenDecodeEntities
bcf091
bcf091
Found with libFuzzer.
bcf091
bcf091
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
bcf091
---
bcf091
 parser.c | 3 ++-
bcf091
 1 file changed, 2 insertions(+), 1 deletion(-)
bcf091
bcf091
diff --git a/parser.c b/parser.c
bcf091
index d1c31963..a34bb6cd 100644
bcf091
--- a/parser.c
bcf091
+++ b/parser.c
bcf091
@@ -2646,7 +2646,8 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
bcf091
     else
bcf091
         c = 0;
bcf091
     while ((c != 0) && (c != end) && /* non input consuming loop */
bcf091
-	   (c != end2) && (c != end3)) {
bcf091
+           (c != end2) && (c != end3) &&
bcf091
+           (ctxt->instate != XML_PARSER_EOF)) {
bcf091
 
bcf091
 	if (c == 0) break;
bcf091
         if ((c == '&') && (str[1] == '#')) {
bcf091
-- 
bcf091
2.24.1
bcf091