2
1

0001-tree-Fix-integer-overflow-in-xmlBuildQName.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 719cfb3f3893c7f8fada2ad71fabb68c5fe953bf Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Tue, 27 May 2025 12:53:17 +0200
  4. Subject: [PATCH] tree: Fix integer overflow in xmlBuildQName
  5. This issue affects memory safety and might receive a CVE ID later.
  6. Fixes #926.
  7. Signed-off-by: Tim Soubry <tim.soubry@mind.be>
  8. Upstream: https://gitlab.gnome.org/GNOME/libxml2/-/commit/ad346c9a249c4b380bf73c460ad3e81135c5d781
  9. CVE: CVE-2025-6021
  10. [tim: include needed stdint header]
  11. ---
  12. tree.c | 11 +++++++----
  13. 1 file changed, 7 insertions(+), 4 deletions(-)
  14. diff --git a/tree.c b/tree.c
  15. index f097cf87..53385568 100644
  16. --- a/tree.c
  17. +++ b/tree.c
  18. @@ -23,6 +23,7 @@
  19. #include <limits.h>
  20. #include <ctype.h>
  21. #include <stdlib.h>
  22. +#include <stdint.h>
  23. #ifdef LIBXML_ZLIB_ENABLED
  24. #include <zlib.h>
  25. @@ -167,10 +168,10 @@ xmlGetParameterEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) {
  26. xmlChar *
  27. xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix,
  28. xmlChar *memory, int len) {
  29. - int lenn, lenp;
  30. + size_t lenn, lenp;
  31. xmlChar *ret;
  32. - if (ncname == NULL) return(NULL);
  33. + if ((ncname == NULL) || (len < 0)) return(NULL);
  34. if (prefix == NULL) return((xmlChar *) ncname);
  35. #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  36. @@ -181,9 +182,11 @@ xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix,
  37. lenn = strlen((char *) ncname);
  38. lenp = strlen((char *) prefix);
  39. + if (lenn >= SIZE_MAX - lenp - 1)
  40. + return(NULL);
  41. - if ((memory == NULL) || (len < lenn + lenp + 2)) {
  42. - ret = (xmlChar *) xmlMallocAtomic(lenn + lenp + 2);
  43. + if ((memory == NULL) || ((size_t) len < lenn + lenp + 2)) {
  44. + ret = xmlMalloc(lenn + lenp + 2);
  45. if (ret == NULL)
  46. return(NULL);
  47. } else {
  48. --
  49. 2.39.5