mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Fix core dump in contrib/xml2's xpath_table() when the input query returns
a NULL value. Per bug #4058.
This commit is contained in:
parent
0a11e1063d
commit
270b3adb16
@ -808,12 +808,10 @@ xpath_table(PG_FUNCTION_ARGS)
|
|||||||
xmlXPathCompExprPtr comppath;
|
xmlXPathCompExprPtr comppath;
|
||||||
|
|
||||||
/* Extract the row data as C Strings */
|
/* Extract the row data as C Strings */
|
||||||
|
|
||||||
spi_tuple = tuptable->vals[i];
|
spi_tuple = tuptable->vals[i];
|
||||||
pkey = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
|
pkey = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
|
||||||
xmldoc = SPI_getvalue(spi_tuple, spi_tupdesc, 2);
|
xmldoc = SPI_getvalue(spi_tuple, spi_tupdesc, 2);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear the values array, so that not-well-formed documents return
|
* Clear the values array, so that not-well-formed documents return
|
||||||
* NULL in all columns.
|
* NULL in all columns.
|
||||||
@ -827,11 +825,14 @@ xpath_table(PG_FUNCTION_ARGS)
|
|||||||
values[0] = pkey;
|
values[0] = pkey;
|
||||||
|
|
||||||
/* Parse the document */
|
/* Parse the document */
|
||||||
|
if (xmldoc)
|
||||||
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
|
doctree = xmlParseMemory(xmldoc, strlen(xmldoc));
|
||||||
|
else /* treat NULL as not well-formed */
|
||||||
|
doctree = NULL;
|
||||||
|
|
||||||
if (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);
|
ret_tuple = BuildTupleFromCStrings(attinmeta, values);
|
||||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
||||||
tuplestore_puttuple(tupstore, ret_tuple);
|
tuplestore_puttuple(tupstore, ret_tuple);
|
||||||
@ -923,7 +924,9 @@ xpath_table(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
xmlFreeDoc(doctree);
|
xmlFreeDoc(doctree);
|
||||||
|
|
||||||
|
if (pkey)
|
||||||
pfree(pkey);
|
pfree(pkey);
|
||||||
|
if (xmldoc)
|
||||||
pfree(xmldoc);
|
pfree(xmldoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user