You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. From 50f06b3efb638efb0abd95dc62dca05ae67882c2 Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Fri, 7 Aug 2020 21:54:27 +0200
  4. Subject: [PATCH] Fix out-of-bounds read with 'xmllint --htmlout'
  5. Make sure that truncated UTF-8 sequences don't cause an out-of-bounds
  6. array access.
  7. Thanks to @SuhwanSong and the Agency for Defense Development (ADD) for
  8. the report.
  9. Fixes #178.
  10. ---
  11. xmllint.c | 6 ++++++
  12. 1 file changed, 6 insertions(+)
  13. diff --git a/xmllint.c b/xmllint.c
  14. index f6a8e4636..c647486f3 100644
  15. --- a/xmllint.c
  16. +++ b/xmllint.c
  17. @@ -528,6 +528,12 @@ static void
  18. xmlHTMLEncodeSend(void) {
  19. char *result;
  20. + /*
  21. + * xmlEncodeEntitiesReentrant assumes valid UTF-8, but the buffer might
  22. + * end with a truncated UTF-8 sequence. This is a hack to at least avoid
  23. + * an out-of-bounds read.
  24. + */
  25. + memset(&buffer[sizeof(buffer)-4], 0, 4);
  26. result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
  27. if (result) {
  28. xmlGenericError(xmlGenericErrorContext, "%s", result);
  29. --
  30. GitLab