0011-Fix-use-after-free-in-xsltDocumentFunctionLoadDocume.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From fc1ff481fd01e9a65a921c542fed68d8c965e8a3 Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Thu, 25 Feb 2016 17:16:06 +0100
  4. Subject: [PATCH] Fix use-after-free in xsltDocumentFunctionLoadDocument
  5. Also fixes a memory leak in an unlikely error case.
  6. Fixes bug #758291
  7. https://bugzilla.gnome.org/show_bug.cgi?id=758291
  8. ---
  9. libxslt/functions.c | 3 ++-
  10. tests/docs/bug-185-data.xml | 5 +++++
  11. tests/docs/bug-185.xml | 2 ++
  12. tests/general/bug-185.err | 3 +++
  13. tests/general/bug-185.out | 0
  14. tests/general/bug-185.xsl | 14 ++++++++++++++
  15. 6 files changed, 26 insertions(+), 1 deletion(-)
  16. create mode 100644 tests/docs/bug-185-data.xml
  17. create mode 100644 tests/docs/bug-185.xml
  18. create mode 100644 tests/general/bug-185.err
  19. create mode 100644 tests/general/bug-185.out
  20. create mode 100644 tests/general/bug-185.xsl
  21. diff --git a/libxslt/functions.c b/libxslt/functions.c
  22. index 549649c..a5e7021 100644
  23. --- a/libxslt/functions.c
  24. +++ b/libxslt/functions.c
  25. @@ -180,7 +180,6 @@ xsltDocumentFunctionLoadDocument(xmlXPathParserContextPtr ctxt, xmlChar* URI)
  26. resObj = xmlXPtrEval(fragment, xptrctxt);
  27. xmlXPathFreeContext(xptrctxt);
  28. #endif
  29. - xmlFree(fragment);
  30. if (resObj == NULL)
  31. goto out_fragment;
  32. @@ -204,6 +203,7 @@ xsltDocumentFunctionLoadDocument(xmlXPathParserContextPtr ctxt, xmlChar* URI)
  33. }
  34. valuePush(ctxt, resObj);
  35. + xmlFree(fragment);
  36. return;
  37. out_object:
  38. @@ -211,6 +211,7 @@ out_object:
  39. out_fragment:
  40. valuePush(ctxt, xmlXPathNewNodeSet(NULL));
  41. + xmlFree(fragment);
  42. }
  43. /**
  44. diff --git a/tests/docs/bug-185-data.xml b/tests/docs/bug-185-data.xml
  45. new file mode 100644
  46. index 0000000..166ef17
  47. --- /dev/null
  48. +++ b/tests/docs/bug-185-data.xml
  49. @@ -0,0 +1,5 @@
  50. +<!DOCTYPE test [ <!ATTLIST A id ID #REQUIRED> ] >
  51. +<test>
  52. + <A id="X"/>
  53. + <A id="Y"/>
  54. +</test>
  55. diff --git a/tests/docs/bug-185.xml b/tests/docs/bug-185.xml
  56. new file mode 100644
  57. index 0000000..72bfdc4
  58. --- /dev/null
  59. +++ b/tests/docs/bug-185.xml
  60. @@ -0,0 +1,2 @@
  61. +<?xml-stylesheet href="poc.xsl" type="text/xsl"?>
  62. +<in>bug-185-data.xml#xpointer(id('X')/range-to(id('Y')))</in>
  63. diff --git a/tests/general/bug-185.err b/tests/general/bug-185.err
  64. new file mode 100644
  65. index 0000000..d7bbe92
  66. --- /dev/null
  67. +++ b/tests/general/bug-185.err
  68. @@ -0,0 +1,3 @@
  69. +runtime error: file ./bug-185.xsl line 7 element copy-of
  70. +document() : XPointer does not select a node set: #xpointer(id('X')/range-to(id('Y')))
  71. +no result for ./../docs/bug-185.xml
  72. diff --git a/tests/general/bug-185.out b/tests/general/bug-185.out
  73. new file mode 100644
  74. index 0000000..e69de29
  75. diff --git a/tests/general/bug-185.xsl b/tests/general/bug-185.xsl
  76. new file mode 100644
  77. index 0000000..1c5c7d1
  78. --- /dev/null
  79. +++ b/tests/general/bug-185.xsl
  80. @@ -0,0 +1,14 @@
  81. +<?xml version="1.0" encoding="utf-8"?>
  82. +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  83. + <xsl:template match="in">
  84. + <annotation>
  85. + <xsl:copy-of select="."/>
  86. + <value>
  87. + <xsl:copy-of select="document(.)"/>
  88. + </value>
  89. + </annotation>
  90. + </xsl:template>
  91. + <xsl:template match="@*|node()">
  92. + <xsl:apply-templates/>
  93. + </xsl:template>
  94. +</xsl:stylesheet>
  95. --
  96. 2.8.1