summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/xml.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-05-28 12:36:04 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-05-28 12:36:41 -0400
commitf064a4f2633088ffb3269907fe58d9a410dc021f (patch)
treed592a1d10de726c25fdf6864bf9934d4ca91fc5e /src/backend/utils/adt/xml.c
parentf014211849e405b1784f0bfc9d4f6bd7d06f269f (diff)
Fix null-dereference crash in parse_xml_decl().
parse_xml_decl's header comment says you can pass NULL for any unwanted output parameter, but it failed to honor this contract for the "standalone" flag. The only currently-affected caller is xml_recv, so the net effect is that sending a binary XML value containing a standalone parameter in its xml declaration would crash the backend. Per bug #6044 from Christopher Dillard. In passing, remove useless initializations of parse_xml_decl's output parameters in xml_parse. Back-patch to 8.3, where this code was introduced.
Diffstat (limited to 'src/backend/utils/adt/xml.c')
-rw-r--r--src/backend/utils/adt/xml.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 9ce642f8556..e96eec6da84 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -1104,13 +1104,15 @@ parse_xml_decl(const xmlChar *str, size_t *lenp,
if (xmlStrncmp(p, (xmlChar *) "'yes'", 5) == 0 ||
xmlStrncmp(p, (xmlChar *) "\"yes\"", 5) == 0)
{
- *standalone = 1;
+ if (standalone)
+ *standalone = 1;
p += 5;
}
else if (xmlStrncmp(p, (xmlChar *) "'no'", 4) == 0 ||
xmlStrncmp(p, (xmlChar *) "\"no\"", 4) == 0)
{
- *standalone = 0;
+ if (standalone)
+ *standalone = 0;
p += 4;
}
else
@@ -1254,8 +1256,8 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace,
{
int res_code;
size_t count;
- xmlChar *version = NULL;
- int standalone = -1;
+ xmlChar *version;
+ int standalone;
res_code = parse_xml_decl(utf8string,
&count, &version, NULL, &standalone);