postgres.git / summary / log / commit / refs

commit    e5e66ac021fbbe4fd60b98511b68b6157ff2273a
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Wed Mar 26 01:19:31 2008 +0000
First released in: 8.4.0, 8.0.16, 8.1.12, 8.2.8, 8.3.2

    Fix core dump in contrib/xml2's xpath_table() when the input query returns
    a NULL value.  Per bug #4058.


contrib/xml2/xpath.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index c15a5bb6225..268937e38bc 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -801,12 +801,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. @@ -820,12 +818,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); @@ -917,8 +917,10 @@ xpath_table(PG_FUNCTION_ARGS) xmlFreeDoc(doctree); - pfree(pkey); - pfree(xmldoc); + if (pkey) + pfree(pkey); + if (xmldoc) + pfree(xmldoc); } xmlCleanupParser(); [parent: c1df51585f17]