0016-Lower-and-upper-bound-for-format-token-i.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. From 91d0540ac9beaa86719a05b749219a69baa0dd8d Mon Sep 17 00:00:00 2001
  2. From: Nick Wellnhofer <wellnhofer@aevum.de>
  3. Date: Sun, 10 Apr 2016 13:12:28 +0200
  4. Subject: [PATCH] Lower and upper bound for format token "i"
  5. Handle xsl:number with format "i" and value 0 according to XSLT 2.0.
  6. Also introduce an upper bound to fix a denial of service.
  7. ---
  8. libxslt/numbers.c | 25 ++++++++++++++++---------
  9. 1 file changed, 16 insertions(+), 9 deletions(-)
  10. diff --git a/libxslt/numbers.c b/libxslt/numbers.c
  11. index af52883..e769c42 100644
  12. --- a/libxslt/numbers.c
  13. +++ b/libxslt/numbers.c
  14. @@ -274,11 +274,24 @@ xsltNumberFormatAlpha(xsltNumberDataPtr data,
  15. }
  16. static void
  17. -xsltNumberFormatRoman(xmlBufferPtr buffer,
  18. +xsltNumberFormatRoman(xsltNumberDataPtr data,
  19. + xmlBufferPtr buffer,
  20. double number,
  21. int is_upper)
  22. {
  23. /*
  24. + * See discussion in xsltNumberFormatAlpha. Also use a reasonable upper
  25. + * bound to avoid denial of service.
  26. + */
  27. + if (number < 1.0 || number > 5000.0) {
  28. + xsltNumberFormatDecimal(buffer, number, '0', 1,
  29. + data->digitsPerGroup,
  30. + data->groupingCharacter,
  31. + data->groupingCharacterLen);
  32. + return;
  33. + }
  34. +
  35. + /*
  36. * Based on an example by Jim Walsh
  37. */
  38. while (number >= 1000.0) {
  39. @@ -527,16 +540,10 @@ xsltNumberFormatInsertNumbers(xsltNumberDataPtr data,
  40. xsltNumberFormatAlpha(data, buffer, number, FALSE);
  41. break;
  42. case 'I':
  43. - xsltNumberFormatRoman(buffer,
  44. - number,
  45. - TRUE);
  46. -
  47. + xsltNumberFormatRoman(data, buffer, number, TRUE);
  48. break;
  49. case 'i':
  50. - xsltNumberFormatRoman(buffer,
  51. - number,
  52. - FALSE);
  53. -
  54. + xsltNumberFormatRoman(data, buffer, number, FALSE);
  55. break;
  56. default:
  57. if (IS_DIGIT_ZERO(token->token)) {
  58. --
  59. 2.8.1