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.

120 lines
3.9 KiB

  1. From e03553605b45c88f0b4b2980adfbbb8f6fca2fd6 Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Sun, 24 Mar 2019 09:51:39 +0100
  4. Subject: [PATCH] Fix security framework bypass
  5. xsltCheckRead and xsltCheckWrite return -1 in case of error but callers
  6. don't check for this condition and allow access. With a specially
  7. crafted URL, xsltCheckRead could be tricked into returning an error
  8. because of a supposedly invalid URL that would still be loaded
  9. succesfully later on.
  10. Fixes #12.
  11. Thanks to Felix Wilhelm for the report.
  12. ---
  13. libxslt/documents.c | 18 ++++++++++--------
  14. libxslt/imports.c | 9 +++++----
  15. libxslt/transform.c | 9 +++++----
  16. libxslt/xslt.c | 9 +++++----
  17. 4 files changed, 25 insertions(+), 20 deletions(-)
  18. diff --git a/libxslt/documents.c b/libxslt/documents.c
  19. index 3f3a7312..4aad11bb 100644
  20. --- a/libxslt/documents.c
  21. +++ b/libxslt/documents.c
  22. @@ -296,10 +296,11 @@ xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) {
  23. int res;
  24. res = xsltCheckRead(ctxt->sec, ctxt, URI);
  25. - if (res == 0) {
  26. - xsltTransformError(ctxt, NULL, NULL,
  27. - "xsltLoadDocument: read rights for %s denied\n",
  28. - URI);
  29. + if (res <= 0) {
  30. + if (res == 0)
  31. + xsltTransformError(ctxt, NULL, NULL,
  32. + "xsltLoadDocument: read rights for %s denied\n",
  33. + URI);
  34. return(NULL);
  35. }
  36. }
  37. @@ -372,10 +373,11 @@ xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI) {
  38. int res;
  39. res = xsltCheckRead(sec, NULL, URI);
  40. - if (res == 0) {
  41. - xsltTransformError(NULL, NULL, NULL,
  42. - "xsltLoadStyleDocument: read rights for %s denied\n",
  43. - URI);
  44. + if (res <= 0) {
  45. + if (res == 0)
  46. + xsltTransformError(NULL, NULL, NULL,
  47. + "xsltLoadStyleDocument: read rights for %s denied\n",
  48. + URI);
  49. return(NULL);
  50. }
  51. }
  52. diff --git a/libxslt/imports.c b/libxslt/imports.c
  53. index 874870cc..3783b247 100644
  54. --- a/libxslt/imports.c
  55. +++ b/libxslt/imports.c
  56. @@ -130,10 +130,11 @@ xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) {
  57. int secres;
  58. secres = xsltCheckRead(sec, NULL, URI);
  59. - if (secres == 0) {
  60. - xsltTransformError(NULL, NULL, NULL,
  61. - "xsl:import: read rights for %s denied\n",
  62. - URI);
  63. + if (secres <= 0) {
  64. + if (secres == 0)
  65. + xsltTransformError(NULL, NULL, NULL,
  66. + "xsl:import: read rights for %s denied\n",
  67. + URI);
  68. goto error;
  69. }
  70. }
  71. diff --git a/libxslt/transform.c b/libxslt/transform.c
  72. index 13793914..0636dbd0 100644
  73. --- a/libxslt/transform.c
  74. +++ b/libxslt/transform.c
  75. @@ -3493,10 +3493,11 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
  76. */
  77. if (ctxt->sec != NULL) {
  78. ret = xsltCheckWrite(ctxt->sec, ctxt, filename);
  79. - if (ret == 0) {
  80. - xsltTransformError(ctxt, NULL, inst,
  81. - "xsltDocumentElem: write rights for %s denied\n",
  82. - filename);
  83. + if (ret <= 0) {
  84. + if (ret == 0)
  85. + xsltTransformError(ctxt, NULL, inst,
  86. + "xsltDocumentElem: write rights for %s denied\n",
  87. + filename);
  88. xmlFree(URL);
  89. xmlFree(filename);
  90. return;
  91. diff --git a/libxslt/xslt.c b/libxslt/xslt.c
  92. index 780a5ad7..a234eb79 100644
  93. --- a/libxslt/xslt.c
  94. +++ b/libxslt/xslt.c
  95. @@ -6763,10 +6763,11 @@ xsltParseStylesheetFile(const xmlChar* filename) {
  96. int res;
  97. res = xsltCheckRead(sec, NULL, filename);
  98. - if (res == 0) {
  99. - xsltTransformError(NULL, NULL, NULL,
  100. - "xsltParseStylesheetFile: read rights for %s denied\n",
  101. - filename);
  102. + if (res <= 0) {
  103. + if (res == 0)
  104. + xsltTransformError(NULL, NULL, NULL,
  105. + "xsltParseStylesheetFile: read rights for %s denied\n",
  106. + filename);
  107. return(NULL);
  108. }
  109. }
  110. --
  111. 2.18.1