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.

71 lines
2.3 KiB

  1. From 6ce8de69330783977dd14f6569419489875fb71b Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Mon, 3 Jun 2019 13:14:45 +0200
  4. Subject: [PATCH] Fix uninitialized read with UTF-8 grouping chars
  5. The character type in xsltFormatNumberConversion was too narrow and
  6. an invalid character/length combination could be passed to
  7. xsltNumberFormatDecimal, resulting in an uninitialized read.
  8. Found by OSS-Fuzz.
  9. ---
  10. libxslt/numbers.c | 5 +++--
  11. tests/docs/bug-222.xml | 1 +
  12. tests/general/bug-222.out | 2 ++
  13. tests/general/bug-222.xsl | 6 ++++++
  14. 4 files changed, 12 insertions(+), 2 deletions(-)
  15. create mode 100644 tests/docs/bug-222.xml
  16. create mode 100644 tests/general/bug-222.out
  17. create mode 100644 tests/general/bug-222.xsl
  18. diff --git a/libxslt/numbers.c b/libxslt/numbers.c
  19. index f1ed8846..20b99d5a 100644
  20. --- a/libxslt/numbers.c
  21. +++ b/libxslt/numbers.c
  22. @@ -1298,13 +1298,14 @@ OUTPUT_NUMBER:
  23. number = floor((scale * number + 0.5)) / scale;
  24. if ((self->grouping != NULL) &&
  25. (self->grouping[0] != 0)) {
  26. + int gchar;
  27. len = xmlStrlen(self->grouping);
  28. - pchar = xsltGetUTF8Char(self->grouping, &len);
  29. + gchar = xsltGetUTF8Char(self->grouping, &len);
  30. xsltNumberFormatDecimal(buffer, floor(number), self->zeroDigit[0],
  31. format_info.integer_digits,
  32. format_info.group,
  33. - pchar, len);
  34. + gchar, len);
  35. } else
  36. xsltNumberFormatDecimal(buffer, floor(number), self->zeroDigit[0],
  37. format_info.integer_digits,
  38. diff --git a/tests/docs/bug-222.xml b/tests/docs/bug-222.xml
  39. new file mode 100644
  40. index 00000000..69d62f2c
  41. --- /dev/null
  42. +++ b/tests/docs/bug-222.xml
  43. @@ -0,0 +1 @@
  44. +<doc/>
  45. diff --git a/tests/general/bug-222.out b/tests/general/bug-222.out
  46. new file mode 100644
  47. index 00000000..e3139698
  48. --- /dev/null
  49. +++ b/tests/general/bug-222.out
  50. @@ -0,0 +1,2 @@
  51. +<?xml version="1.0"?>
  52. +1⠢0
  53. diff --git a/tests/general/bug-222.xsl b/tests/general/bug-222.xsl
  54. new file mode 100644
  55. index 00000000..e32dc473
  56. --- /dev/null
  57. +++ b/tests/general/bug-222.xsl
  58. @@ -0,0 +1,6 @@
  59. +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  60. + <xsl:decimal-format name="f" grouping-separator="⠢"/>
  61. + <xsl:template match="/">
  62. + <xsl:value-of select="format-number(10,'#⠢0','f')"/>
  63. + </xsl:template>
  64. +</xsl:stylesheet>
  65. --
  66. 2.21.0