0008-Fix-attribute-decoding-during-XML-schema-validation.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From 256366ed60f8795279b25f7b7b55e8089b4c6ff4 Mon Sep 17 00:00:00 2001
  2. From: Alex Henrie <alexhenrie24@gmail.com>
  3. Date: Thu, 26 May 2016 17:38:35 -0600
  4. Subject: [PATCH] Fix attribute decoding during XML schema validation
  5. For https://bugzilla.gnome.org/show_bug.cgi?id=766834
  6. vctxt->parserCtxt is always NULL in xmlSchemaSAXHandleStartElementNs,
  7. so this function can't call xmlStringLenDecodeEntities to decode the
  8. entities.
  9. ---
  10. xmlschemas.c | 30 +++++++++++++++++++++++++-----
  11. 1 file changed, 25 insertions(+), 5 deletions(-)
  12. diff --git a/xmlschemas.c b/xmlschemas.c
  13. index e1b3a4f..59535e5 100644
  14. --- a/xmlschemas.c
  15. +++ b/xmlschemas.c
  16. @@ -27391,6 +27391,7 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
  17. * attributes yet.
  18. */
  19. if (nb_attributes != 0) {
  20. + int valueLen, k, l;
  21. xmlChar *value;
  22. for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
  23. @@ -27400,12 +27401,31 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
  24. * libxml2 differs from normal SAX here in that it escapes all ampersands
  25. * as &#38; instead of delivering the raw converted string. Changing the
  26. * behavior at this point would break applications that use this API, so
  27. - * we are forced to work around it. There is no danger of accidentally
  28. - * decoding some entity other than &#38; in this step because without
  29. - * unescaped ampersands there can be no other entities in the string.
  30. + * we are forced to work around it.
  31. */
  32. - value = xmlStringLenDecodeEntities(vctxt->parserCtxt, attributes[j+3],
  33. - attributes[j+4] - attributes[j+3], XML_SUBSTITUTE_REF, 0, 0, 0);
  34. + valueLen = attributes[j+4] - attributes[j+3];
  35. + value = xmlMallocAtomic(valueLen + 1);
  36. + if (value == NULL) {
  37. + xmlSchemaVErrMemory(vctxt,
  38. + "allocating string for decoded attribute",
  39. + NULL);
  40. + goto internal_error;
  41. + }
  42. + for (k = 0, l = 0; k < valueLen; l++) {
  43. + if (k < valueLen - 4 &&
  44. + attributes[j+3][k+0] == '&' &&
  45. + attributes[j+3][k+1] == '#' &&
  46. + attributes[j+3][k+2] == '3' &&
  47. + attributes[j+3][k+3] == '8' &&
  48. + attributes[j+3][k+4] == ';') {
  49. + value[l] = '&';
  50. + k += 5;
  51. + } else {
  52. + value[l] = attributes[j+3][k];
  53. + k++;
  54. + }
  55. + }
  56. + value[l] = '\0';
  57. /*
  58. * TODO: Set the node line.
  59. */
  60. --
  61. 2.8.3