Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8aad333

Browse files
committed
Fix crash of xmlconcat(NULL)
also backpatched to 8.3
1 parent 0656ed3 commit 8aad333

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

src/backend/executor/execQual.c

+24-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.236 2008/10/31 19:37:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.237 2008/11/15 20:52:35 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3163,13 +3163,10 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
31633163
bool *isNull, ExprDoneCond *isDone)
31643164
{
31653165
XmlExpr *xexpr = (XmlExpr *) xmlExpr->xprstate.expr;
3166-
text *result;
3167-
StringInfoData buf;
31683166
Datum value;
31693167
bool isnull;
31703168
ListCell *arg;
31713169
ListCell *narg;
3172-
int i;
31733170

31743171
if (isDone)
31753172
*isDone = ExprSingleResult;
@@ -3195,12 +3192,16 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
31953192
*isNull = false;
31963193
return PointerGetDatum(xmlconcat(values));
31973194
}
3195+
else
3196+
return (Datum) 0;
31983197
}
31993198
break;
32003199

32013200
case IS_XMLFOREST:
3201+
{
3202+
StringInfoData buf;
3203+
32023204
initStringInfo(&buf);
3203-
i = 0;
32043205
forboth(arg, xmlExpr->named_args, narg, xexpr->arg_names)
32053206
{
32063207
ExprState *e = (ExprState *) lfirst(arg);
@@ -3215,11 +3216,25 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
32153216
argname);
32163217
*isNull = false;
32173218
}
3218-
i++;
32193219
}
3220+
3221+
if (*isNull)
3222+
{
3223+
pfree(buf.data);
3224+
return (Datum) 0;
3225+
}
3226+
else
3227+
{
3228+
text *result;
3229+
3230+
result = cstring_to_text_with_len(buf.data, buf.len);
3231+
pfree(buf.data);
3232+
3233+
return PointerGetDatum(result);
3234+
}
3235+
}
32203236
break;
32213237

3222-
/* The remaining cases don't need to set up buf */
32233238
case IS_XMLELEMENT:
32243239
*isNull = false;
32253240
return PointerGetDatum(xmlelement(xmlExpr, econtext));
@@ -3354,13 +3369,8 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
33543369
break;
33553370
}
33563371

3357-
if (*isNull)
3358-
result = NULL;
3359-
else
3360-
result = cstring_to_text_with_len(buf.data, buf.len);
3361-
3362-
pfree(buf.data);
3363-
return PointerGetDatum(result);
3372+
elog(ERROR, "unrecognized XML operation");
3373+
return (Datum) 0;
33643374
}
33653375

33663376
/* ----------------------------------------------------------------

src/test/regress/expected/xml.out

+12
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" stand
7777
<?xml version="1.1"?><foo/><bar/>
7878
(1 row)
7979

80+
SELECT xmlconcat(NULL);
81+
xmlconcat
82+
-----------
83+
84+
(1 row)
85+
86+
SELECT xmlconcat(NULL, NULL);
87+
xmlconcat
88+
-----------
89+
90+
(1 row)
91+
8092
SELECT xmlelement(name element,
8193
xmlattributes (1 as one, 'deuce' as two),
8294
'content');

src/test/regress/expected/xml_1.out

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ LINE 1: SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml...
7979
^
8080
DETAIL: This functionality requires the server to be built with libxml support.
8181
HINT: You need to rebuild PostgreSQL using --with-libxml.
82+
SELECT xmlconcat(NULL);
83+
xmlconcat
84+
-----------
85+
86+
(1 row)
87+
88+
SELECT xmlconcat(NULL, NULL);
89+
xmlconcat
90+
-----------
91+
92+
(1 row)
93+
8294
SELECT xmlelement(name element,
8395
xmlattributes (1 as one, 'deuce' as two),
8496
'content');

src/test/regress/sql/xml.sql

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ SELECT xmlconcat(1, 2);
2626
SELECT xmlconcat('bad', '<syntax');
2727
SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
2828
SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
29+
SELECT xmlconcat(NULL);
30+
SELECT xmlconcat(NULL, NULL);
2931

3032

3133
SELECT xmlelement(name element,

0 commit comments

Comments
 (0)