From 4d7dfba737aa8cc774b56a04be747d1e436ee4ff Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Jan 2024 12:06:07 -0500 Subject: [PATCH 1/4] Fix incompatibilities with libxml2 >= 2.12.0. libxml2 changed the required signature of error handler callbacks to make the passed xmlError struct "const". This is causing build failures on buildfarm member caiman, and no doubt will start showing up in the field quite soon. Add a version check to adjust the declaration of xml_errorHandler() according to LIBXML_VERSION. 2.12.x also produces deprecation warnings for contrib/xml2/xpath.c's assignment to xmlLoadExtDtdDefaultValue. I see no good reason for that to still be there, seeing that we disabled external DTDs (at a lower level) years ago for security reasons. Let's just remove it. Back-patch to all supported branches, since they might all get built with newer libxml2 once it gets a bit more popular. (The back branches produce another deprecation warning about xpath.c's use of xmlSubstituteEntitiesDefault(). We ought to consider whether to back-patch all or part of commit 65c5864d7 to silence that. It's less urgent though, since it won't break the buildfarm.) Discussion: https://postgr.es/m/1389505.1706382262@sss.pgh.pa.us --- contrib/xml2/xpath.c | 1 - src/backend/utils/adt/xml.c | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index 1e5b71d9a02..f44caf00200 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -75,7 +75,6 @@ pgxml_parser_init(PgXmlStrictness strictness) xmlInitParser(); xmlSubstituteEntitiesDefault(1); - xmlLoadExtDtdDefaultValue = 1; return xmlerrcxt; } diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 6d38a2d0de2..aafa6203b93 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -65,6 +65,16 @@ #if LIBXML_VERSION >= 20704 #define HAVE_XMLSTRUCTUREDERRORCONTEXT 1 #endif + +/* + * libxml2 2.12 decided to insert "const" into the error handler API. + */ +#if LIBXML_VERSION >= 21200 +#define PgXmlErrorPtr const xmlError * +#else +#define PgXmlErrorPtr xmlErrorPtr +#endif + #endif /* USE_LIBXML */ #include "access/htup_details.h" @@ -121,7 +131,7 @@ struct PgXmlErrorContext static xmlParserInputPtr xmlPgEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt); -static void xml_errorHandler(void *data, xmlErrorPtr error); +static void xml_errorHandler(void *data, PgXmlErrorPtr error); static void xml_ereport_by_code(int level, int sqlcode, const char *msg, int errcode); static void chopStringInfoNewlines(StringInfo str); @@ -1762,7 +1772,7 @@ xml_ereport(PgXmlErrorContext *errcxt, int level, int sqlcode, const char *msg) * Error handler for libxml errors and warnings */ static void -xml_errorHandler(void *data, xmlErrorPtr error) +xml_errorHandler(void *data, PgXmlErrorPtr error) { PgXmlErrorContext *xmlerrcxt = (PgXmlErrorContext *) data; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt; From 4b353ca3803d2af83a5e0283a5d9723f3902b059 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 1 Apr 2024 19:01:18 -0400 Subject: [PATCH 2/4] Avoid "unused variable" warning on non-USE_SSL_ENGINE platforms. If we are building with openssl but USE_SSL_ENGINE didn't get set, initialize_SSL's variable "pkey" is declared but used nowhere. Apparently this combination hasn't been exercised in the buildfarm before now, because I've not seen this warning before, even though the code has been like this a long time. Move the declaration to silence the warning (and remove its useless initialization). Per buildfarm member sawshark. Back-patch to all supported branches. --- src/interfaces/libpq/fe-secure-openssl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 5c6b317caa7..ccd886abb84 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -797,7 +797,6 @@ initialize_SSL(PGconn *conn) bool have_homedir; bool have_cert; bool have_rootcert; - EVP_PKEY *pkey = NULL; /* * We'll need the home directory if any of the relevant parameters are @@ -1133,6 +1132,7 @@ initialize_SSL(PGconn *conn) /* Colon, but not in second character, treat as engine:key */ char *engine_str = strdup(conn->sslkey); char *engine_colon; + EVP_PKEY *pkey; if (engine_str == NULL) { From b275085c45016709133863fa04b434e565254589 Mon Sep 17 00:00:00 2001 From: Leonid Borchuk Date: Mon, 13 Apr 2026 16:20:34 +0000 Subject: [PATCH 3/4] Do not include protobuf files twice We have two sections in a Makefile - one for CPP_OBJS and one for OBJS. CPP_OBJS use wildcards and src/protos includes bot in CPP_OBJS and in OBJS. So generated gcc string includes multiple items of proto *.o files. That leads to multiple definitions errors in linking time. Do not include proto files in CPP_OBJS macros and use it in OBJS macros. --- gpcontrib/gp_stats_collector/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpcontrib/gp_stats_collector/Makefile b/gpcontrib/gp_stats_collector/Makefile index 43255ca1955..b3228d2c45e 100644 --- a/gpcontrib/gp_stats_collector/Makefile +++ b/gpcontrib/gp_stats_collector/Makefile @@ -7,7 +7,7 @@ PROTO_BASES = gpsc_plan gpsc_metrics gpsc_set_service PROTO_OBJS = $(patsubst %,src/protos/%.pb.o,$(PROTO_BASES)) C_OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c src/*/*.c)) -CPP_OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp src/*/*.cpp)) +CPP_OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp src/log/*.cpp src/memory/*.cpp)) OBJS = $(C_OBJS) $(CPP_OBJS) $(PROTO_OBJS) PG_CXXFLAGS += -Werror -Wall -Wno-unused-but-set-variable -std=c++17 -Isrc/protos -Isrc -Iinclude -DGPBUILD From e246f3895c1ac9978a8208c781ed8d5c20dd8869 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 17 Jan 2024 08:53:16 +0900 Subject: [PATCH 4/4] xml2: Replace deprecated routines with recommended ones Some functions are used in the tree and are currently marked as deprecated by upstream. This commit refreshes the code to use the recommended functions, leading to the following changes: - xmlSubstituteEntitiesDefault() is gone, and needs to be replaced with XML_PARSE_NOENT for the paths doing the parsing. - xmlParseMemory() -> xmlReadMemory(). These functions, as well as more functions setting global states, have been officially marked as deprecated by upstream in August 2022. Their replacements exist since the 2001-ish area, as far as I have checked, so that should be safe. Author: Dmitry Koval Discussion: https://postgr.es/m/18274-98d16bc03520665f@postgresql.org --- contrib/xml2/xpath.c | 10 ++++++---- contrib/xml2/xslt_proc.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index f44caf00200..0555294f234 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -74,7 +74,6 @@ pgxml_parser_init(PgXmlStrictness strictness) /* Initialize libxml */ xmlInitParser(); - xmlSubstituteEntitiesDefault(1); return xmlerrcxt; } @@ -424,8 +423,9 @@ pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace) PG_TRY(); { - workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document), - docsize); + workspace->doctree = xmlReadMemory((char *) VARDATA_ANY(document), + docsize, NULL, NULL, + XML_PARSE_NOENT); if (workspace->doctree != NULL) { workspace->ctxt = xmlXPathNewContext(workspace->doctree); @@ -718,7 +718,9 @@ xpath_table(PG_FUNCTION_ARGS) /* Parse the document */ if (xmldoc) - doctree = xmlParseMemory(xmldoc, strlen(xmldoc)); + doctree = xmlReadMemory(xmldoc, strlen(xmldoc), + NULL, NULL, + XML_PARSE_NOENT); else /* treat NULL as not well-formed */ doctree = NULL; diff --git a/contrib/xml2/xslt_proc.c b/contrib/xml2/xslt_proc.c index 2189bca86ff..f30a3a42c03 100644 --- a/contrib/xml2/xslt_proc.c +++ b/contrib/xml2/xslt_proc.c @@ -85,16 +85,18 @@ xslt_process(PG_FUNCTION_ARGS) bool xslt_sec_prefs_error; /* Parse document */ - doctree = xmlParseMemory((char *) VARDATA_ANY(doct), - VARSIZE_ANY_EXHDR(doct)); + doctree = xmlReadMemory((char *) VARDATA_ANY(doct), + VARSIZE_ANY_EXHDR(doct), NULL, NULL, + XML_PARSE_NOENT); if (doctree == NULL) xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION, "error parsing XML document"); /* Same for stylesheet */ - ssdoc = xmlParseMemory((char *) VARDATA_ANY(ssheet), - VARSIZE_ANY_EXHDR(ssheet)); + ssdoc = xmlReadMemory((char *) VARDATA_ANY(ssheet), + VARSIZE_ANY_EXHDR(ssheet), NULL, NULL, + XML_PARSE_NOENT); if (ssdoc == NULL) xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,