gnome-libxslt-bug-139-apple-fix.diff 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From 345d6826d0eae6f0a962456b8ed6f6a1bad0877d Mon Sep 17 00:00:00 2001
  2. From: David Kilzer <ddkilzer@apple.com>
  3. Date: Sat, 24 May 2025 15:06:42 -0700
  4. Subject: [PATCH] libxslt: Type confusion in xmlNode.psvi between stylesheet
  5. and source nodes
  6. * libxslt/functions.c:
  7. (xsltDocumentFunctionLoadDocument):
  8. - Implement fix suggested by Ivan Fratric. This copies the xmlDoc,
  9. calls xsltCleanupSourceDoc() to remove pvsi fields, then adds the
  10. xmlDoc to tctxt->docList.
  11. - Add error handling for functions that may return NULL.
  12. * libxslt/transform.c:
  13. - Remove static keyword so this can be called from
  14. xsltDocumentFunctionLoadDocument().
  15. * libxslt/transformInternals.h: Add.
  16. (xsltCleanupSourceDoc): Add declaration.
  17. Fixes #139.
  18. CVE: CVE-2025-7424
  19. Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/libxslt/-/issues/139]
  20. Signed-off-by: Ross Burton <ross.burton@arm.com>
  21. ---
  22. libxslt/functions.c | 16 +++++++++++++++-
  23. libxslt/transform.c | 3 ++-
  24. libxslt/transformInternals.h | 9 +++++++++
  25. 3 files changed, 26 insertions(+), 2 deletions(-)
  26. create mode 100644 libxslt/transformInternals.h
  27. diff --git a/libxslt/functions.c b/libxslt/functions.c
  28. index 72a58dc4..11ec039f 100644
  29. --- a/libxslt/functions.c
  30. +++ b/libxslt/functions.c
  31. @@ -34,6 +34,7 @@
  32. #include "numbersInternals.h"
  33. #include "keys.h"
  34. #include "documents.h"
  35. +#include "transformInternals.h"
  36. #ifdef WITH_XSLT_DEBUG
  37. #define WITH_XSLT_DEBUG_FUNCTION
  38. @@ -125,7 +126,20 @@ xsltDocumentFunctionLoadDocument(xmlXPathParserContextPtr ctxt,
  39. /*
  40. * This selects the stylesheet's doc itself.
  41. */
  42. - doc = tctxt->style->doc;
  43. + doc = xmlCopyDoc(tctxt->style->doc, 1);
  44. + if (doc == NULL) {
  45. + xsltTransformError(tctxt, NULL, NULL,
  46. + "document() : failed to copy style doc\n");
  47. + goto out_fragment;
  48. + }
  49. + xsltCleanupSourceDoc(doc); /* Remove psvi fields. */
  50. + idoc = xsltNewDocument(tctxt, doc);
  51. + if (idoc == NULL) {
  52. + xsltTransformError(tctxt, NULL, NULL,
  53. + "document() : failed to create xsltDocument\n");
  54. + xmlFreeDoc(doc);
  55. + goto out_fragment;
  56. + }
  57. } else {
  58. goto out_fragment;
  59. }
  60. diff --git a/libxslt/transform.c b/libxslt/transform.c
  61. index 54ef821b..38c2dce6 100644
  62. --- a/libxslt/transform.c
  63. +++ b/libxslt/transform.c
  64. @@ -43,6 +43,7 @@
  65. #include "xsltlocale.h"
  66. #include "pattern.h"
  67. #include "transform.h"
  68. +#include "transformInternals.h"
  69. #include "variables.h"
  70. #include "numbersInternals.h"
  71. #include "namespaces.h"
  72. @@ -5757,7 +5758,7 @@ xsltCountKeys(xsltTransformContextPtr ctxt)
  73. *
  74. * Resets source node flags and ids stored in 'psvi' member.
  75. */
  76. -static void
  77. +void
  78. xsltCleanupSourceDoc(xmlDocPtr doc) {
  79. xmlNodePtr cur = (xmlNodePtr) doc;
  80. void **psviPtr;
  81. diff --git a/libxslt/transformInternals.h b/libxslt/transformInternals.h
  82. new file mode 100644
  83. index 00000000..d0f42823
  84. --- /dev/null
  85. +++ b/libxslt/transformInternals.h
  86. @@ -0,0 +1,9 @@
  87. +/*
  88. + * Summary: set of internal interfaces for the XSLT engine transformation part.
  89. + *
  90. + * Copy: See Copyright for the status of this software.
  91. + *
  92. + * Author: David Kilzer <ddkilzer@apple.com>
  93. + */
  94. +
  95. +void xsltCleanupSourceDoc(xmlDocPtr doc);
  96. --
  97. 2.39.5 (Apple Git-154)