mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Fix crash of xmlconcat(NULL)
backpatch from 8.4devel
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.226 2008/01/01 19:45:49 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.226.2.1 2008/11/15 20:53:40 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2848,13 +2848,10 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
|
|||||||
bool *isNull, ExprDoneCond *isDone)
|
bool *isNull, ExprDoneCond *isDone)
|
||||||
{
|
{
|
||||||
XmlExpr *xexpr = (XmlExpr *) xmlExpr->xprstate.expr;
|
XmlExpr *xexpr = (XmlExpr *) xmlExpr->xprstate.expr;
|
||||||
text *result;
|
|
||||||
StringInfoData buf;
|
|
||||||
Datum value;
|
Datum value;
|
||||||
bool isnull;
|
bool isnull;
|
||||||
ListCell *arg;
|
ListCell *arg;
|
||||||
ListCell *narg;
|
ListCell *narg;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (isDone)
|
if (isDone)
|
||||||
*isDone = ExprSingleResult;
|
*isDone = ExprSingleResult;
|
||||||
@ -2880,12 +2877,16 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
|
|||||||
*isNull = false;
|
*isNull = false;
|
||||||
return PointerGetDatum(xmlconcat(values));
|
return PointerGetDatum(xmlconcat(values));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return (Datum) 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IS_XMLFOREST:
|
case IS_XMLFOREST:
|
||||||
|
{
|
||||||
|
StringInfoData buf;
|
||||||
|
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
i = 0;
|
|
||||||
forboth(arg, xmlExpr->named_args, narg, xexpr->arg_names)
|
forboth(arg, xmlExpr->named_args, narg, xexpr->arg_names)
|
||||||
{
|
{
|
||||||
ExprState *e = (ExprState *) lfirst(arg);
|
ExprState *e = (ExprState *) lfirst(arg);
|
||||||
@ -2900,11 +2901,30 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
|
|||||||
argname);
|
argname);
|
||||||
*isNull = false;
|
*isNull = false;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*isNull)
|
||||||
|
{
|
||||||
|
pfree(buf.data);
|
||||||
|
return (Datum) 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
text *result;
|
||||||
|
|
||||||
|
len = buf.len + VARHDRSZ;
|
||||||
|
|
||||||
|
result = palloc(len);
|
||||||
|
SET_VARSIZE(result, len);
|
||||||
|
memcpy(VARDATA(result), buf.data, buf.len);
|
||||||
|
pfree(buf.data);
|
||||||
|
|
||||||
|
return PointerGetDatum(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* The remaining cases don't need to set up buf */
|
|
||||||
case IS_XMLELEMENT:
|
case IS_XMLELEMENT:
|
||||||
*isNull = false;
|
*isNull = false;
|
||||||
return PointerGetDatum(xmlelement(xmlExpr, econtext));
|
return PointerGetDatum(xmlelement(xmlExpr, econtext));
|
||||||
@ -3039,19 +3059,8 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*isNull)
|
elog(ERROR, "unrecognized XML operation");
|
||||||
result = NULL;
|
return (Datum) 0;
|
||||||
else
|
|
||||||
{
|
|
||||||
int len = buf.len + VARHDRSZ;
|
|
||||||
|
|
||||||
result = palloc(len);
|
|
||||||
SET_VARSIZE(result, len);
|
|
||||||
memcpy(VARDATA(result), buf.data, buf.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
pfree(buf.data);
|
|
||||||
return PointerGetDatum(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
|
@ -71,6 +71,18 @@ SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" stand
|
|||||||
<?xml version="1.1"?><foo/><bar/>
|
<?xml version="1.1"?><foo/><bar/>
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT xmlconcat(NULL);
|
||||||
|
xmlconcat
|
||||||
|
-----------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT xmlconcat(NULL, NULL);
|
||||||
|
xmlconcat
|
||||||
|
-----------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT xmlelement(name element,
|
SELECT xmlelement(name element,
|
||||||
xmlattributes (1 as one, 'deuce' as two),
|
xmlattributes (1 as one, 'deuce' as two),
|
||||||
'content');
|
'content');
|
||||||
|
@ -63,6 +63,18 @@ SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" stand
|
|||||||
ERROR: unsupported XML feature
|
ERROR: unsupported XML feature
|
||||||
DETAIL: This functionality requires the server to be built with libxml support.
|
DETAIL: This functionality requires the server to be built with libxml support.
|
||||||
HINT: You need to rebuild PostgreSQL using --with-libxml.
|
HINT: You need to rebuild PostgreSQL using --with-libxml.
|
||||||
|
SELECT xmlconcat(NULL);
|
||||||
|
xmlconcat
|
||||||
|
-----------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT xmlconcat(NULL, NULL);
|
||||||
|
xmlconcat
|
||||||
|
-----------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT xmlelement(name element,
|
SELECT xmlelement(name element,
|
||||||
xmlattributes (1 as one, 'deuce' as two),
|
xmlattributes (1 as one, 'deuce' as two),
|
||||||
'content');
|
'content');
|
||||||
|
@ -26,6 +26,8 @@ SELECT xmlconcat(1, 2);
|
|||||||
SELECT xmlconcat('bad', '<syntax');
|
SELECT xmlconcat('bad', '<syntax');
|
||||||
SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
|
SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
|
||||||
SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
|
SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
|
||||||
|
SELECT xmlconcat(NULL);
|
||||||
|
SELECT xmlconcat(NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
SELECT xmlelement(name element,
|
SELECT xmlelement(name element,
|
||||||
|
Reference in New Issue
Block a user