postgresql-14-xml-2.12.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 29e25a6b1eb1b77ecfdbcb5b8dc07c8a6cdcf089 Mon Sep 17 00:00:00 2001
  2. From: Tom Lane <[email protected]>
  3. Date: Mon, 29 Jan 2024 12:06:08 -0500
  4. Subject: [PATCH] Fix incompatibilities with libxml2 >= 2.12.0.
  5. libxml2 changed the required signature of error handler callbacks
  6. to make the passed xmlError struct "const". This is causing build
  7. failures on buildfarm member caiman, and no doubt will start showing
  8. up in the field quite soon. Add a version check to adjust the
  9. declaration of xml_errorHandler() according to LIBXML_VERSION.
  10. 2.12.x also produces deprecation warnings for contrib/xml2/xpath.c's
  11. assignment to xmlLoadExtDtdDefaultValue. I see no good reason for
  12. that to still be there, seeing that we disabled external DTDs (at a
  13. lower level) years ago for security reasons. Let's just remove it.
  14. Back-patch to all supported branches, since they might all get built
  15. with newer libxml2 once it gets a bit more popular. (The back
  16. branches produce another deprecation warning about xpath.c's use of
  17. xmlSubstituteEntitiesDefault(). We ought to consider whether to
  18. back-patch all or part of commit 65c5864d7 to silence that. It's
  19. less urgent though, since it won't break the buildfarm.)
  20. Discussion: https://postgr.es/m/[email protected]
  21. ---
  22. contrib/xml2/xpath.c | 1 -
  23. src/backend/utils/adt/xml.c | 14 ++++++++++++--
  24. 2 files changed, 12 insertions(+), 3 deletions(-)
  25. diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
  26. index 1e5b71d9a0..f44caf0020 100644
  27. --- a/contrib/xml2/xpath.c
  28. +++ b/contrib/xml2/xpath.c
  29. @@ -75,7 +75,6 @@ pgxml_parser_init(PgXmlStrictness strictness)
  30. xmlInitParser();
  31. xmlSubstituteEntitiesDefault(1);
  32. - xmlLoadExtDtdDefaultValue = 1;
  33. return xmlerrcxt;
  34. }
  35. diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
  36. index df7a1b6c40..d7caaaaca0 100644
  37. --- a/src/backend/utils/adt/xml.c
  38. +++ b/src/backend/utils/adt/xml.c
  39. @@ -65,6 +65,16 @@
  40. #if LIBXML_VERSION >= 20704
  41. #define HAVE_XMLSTRUCTUREDERRORCONTEXT 1
  42. #endif
  43. +
  44. +/*
  45. + * libxml2 2.12 decided to insert "const" into the error handler API.
  46. + */
  47. +#if LIBXML_VERSION >= 21200
  48. +#define PgXmlErrorPtr const xmlError *
  49. +#else
  50. +#define PgXmlErrorPtr xmlErrorPtr
  51. +#endif
  52. +
  53. #endif /* USE_LIBXML */
  54. #include "access/htup_details.h"
  55. @@ -119,7 +129,7 @@ struct PgXmlErrorContext
  56. static xmlParserInputPtr xmlPgEntityLoader(const char *URL, const char *ID,
  57. xmlParserCtxtPtr ctxt);
  58. -static void xml_errorHandler(void *data, xmlErrorPtr error);
  59. +static void xml_errorHandler(void *data, PgXmlErrorPtr error);
  60. static void xml_ereport_by_code(int level, int sqlcode,
  61. const char *msg, int errcode);
  62. static void chopStringInfoNewlines(StringInfo str);
  63. @@ -1750,7 +1760,7 @@ xml_ereport(PgXmlErrorContext *errcxt, int level, int sqlcode, const char *msg)
  64. * Error handler for libxml errors and warnings
  65. */
  66. static void
  67. -xml_errorHandler(void *data, xmlErrorPtr error)
  68. +xml_errorHandler(void *data, PgXmlErrorPtr error)
  69. {
  70. PgXmlErrorContext *xmlerrcxt = (PgXmlErrorContext *) data;
  71. xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt;
  72. --
  73. 2.30.2