aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-03-26 01:19:04 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-03-26 01:19:04 +0000
commitff8a1204b40775173284ae8909ddc5fbad3816c0 (patch)
tree14824e0ec7f5f9f513169798cea16c070128eacd
parentc111a7211f758dbcc70fb392aa0949748cadb1e4 (diff)
downloadpostgresql-ff8a1204b40775173284ae8909ddc5fbad3816c0.tar.gz
postgresql-ff8a1204b40775173284ae8909ddc5fbad3816c0.zip
Fix core dump in contrib/xml2's xpath_table() when the input query returns
a NULL value. Per bug #4058.
-rw-r--r--contrib/xml2/xpath.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
index 52cc3d379fd..601733ac874 100644
--- a/contrib/xml2/xpath.c
+++ b/contrib/xml2/xpath.c
@@ -803,12 +803,10 @@ xpath_table(PG_FUNCTION_ARGS)
xmlXPathCompExprPtr comppath;
/* Extract the row data as C Strings */
-
spi_tuple = tuptable->vals[i];
pkey = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
xmldoc = SPI_getvalue(spi_tuple, spi_tupdesc, 2);
-
/*
* Clear the values array, so that not-well-formed documents return
* NULL in all columns.
@@ -822,11 +820,14 @@ xpath_table(PG_FUNCTION_ARGS)
values[0] = pkey;
/* Parse the document */
- doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
+ if (xmldoc)
+ doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
+ else /* treat NULL as not well-formed */
+ doctree = NULL;
if (doctree == NULL)
- { /* not well-formed, so output all-NULL tuple */
-
+ {
+ /* not well-formed, so output all-NULL tuple */
ret_tuple = BuildTupleFromCStrings(attinmeta, values);
oldcontext = MemoryContextSwitchTo(per_query_ctx);
tuplestore_puttuple(tupstore, ret_tuple);
@@ -918,8 +919,10 @@ xpath_table(PG_FUNCTION_ARGS)
xmlFreeDoc(doctree);
- pfree(pkey);
- pfree(xmldoc);
+ if (pkey)
+ pfree(pkey);
+ if (xmldoc)
+ pfree(xmldoc);
}
xmlCleanupParser();