Skip to content

Commit ff8a120

Browse files
committed
Fix core dump in contrib/xml2's xpath_table() when the input query returns
a NULL value. Per bug #4058.
1 parent c111a72 commit ff8a120

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

contrib/xml2/xpath.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,10 @@ xpath_table(PG_FUNCTION_ARGS)
803803
xmlXPathCompExprPtr comppath;
804804

805805
/* Extract the row data as C Strings */
806-
807806
spi_tuple = tuptable->vals[i];
808807
pkey = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
809808
xmldoc = SPI_getvalue(spi_tuple, spi_tupdesc, 2);
810809

811-
812810
/*
813811
* Clear the values array, so that not-well-formed documents return
814812
* NULL in all columns.
@@ -822,11 +820,14 @@ xpath_table(PG_FUNCTION_ARGS)
822820
values[0] = pkey;
823821

824822
/* Parse the document */
825-
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
823+
if (xmldoc)
824+
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
825+
else /* treat NULL as not well-formed */
826+
doctree = NULL;
826827

827828
if (doctree == NULL)
828-
{ /* not well-formed, so output all-NULL tuple */
829-
829+
{
830+
/* not well-formed, so output all-NULL tuple */
830831
ret_tuple = BuildTupleFromCStrings(attinmeta, values);
831832
oldcontext = MemoryContextSwitchTo(per_query_ctx);
832833
tuplestore_puttuple(tupstore, ret_tuple);
@@ -918,8 +919,10 @@ xpath_table(PG_FUNCTION_ARGS)
918919

919920
xmlFreeDoc(doctree);
920921

921-
pfree(pkey);
922-
pfree(xmldoc);
922+
if (pkey)
923+
pfree(pkey);
924+
if (xmldoc)
925+
pfree(xmldoc);
923926
}
924927

925928
xmlCleanupParser();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy