0001-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. From 0e1a49c8907645d2e155f0d89d4d9895ac5112b5 Mon Sep 17 00:00:00 2001
  2. From: Zhipeng Xie <xiezhipeng1@huawei.com>
  3. Date: Thu, 12 Dec 2019 17:30:55 +0800
  4. Subject: [PATCH] Fix infinite loop in xmlStringLenDecodeEntities
  5. When ctxt->instate == XML_PARSER_EOF,xmlParseStringEntityRef
  6. return NULL which cause a infinite loop in xmlStringLenDecodeEntities
  7. Found with libFuzzer.
  8. Fixes CVE-2020-7595: xmlStringLenDecodeEntities in parser.c in libxml2
  9. 2.9.10 has an infinite loop in a certain end-of-file situation.
  10. Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
  11. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  12. ---
  13. parser.c | 3 ++-
  14. 1 file changed, 2 insertions(+), 1 deletion(-)
  15. diff --git a/parser.c b/parser.c
  16. index d1c31963..a34bb6cd 100644
  17. --- a/parser.c
  18. +++ b/parser.c
  19. @@ -2646,7 +2646,8 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
  20. else
  21. c = 0;
  22. while ((c != 0) && (c != end) && /* non input consuming loop */
  23. - (c != end2) && (c != end3)) {
  24. + (c != end2) && (c != end3) &&
  25. + (ctxt->instate != XML_PARSER_EOF)) {
  26. if (c == 0) break;
  27. if ((c == '&') && (str[1] == '#')) {
  28. --
  29. 2.20.1