Skip to content

Commit f064a4f

Browse files
committed
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.
1 parent f014211 commit f064a4f

File tree

1 file changed

+6
-4
lines changed
  • src/backend/utils/adt

1 file changed

+6
-4
lines changed

src/backend/utils/adt/xml.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,13 +1104,15 @@ parse_xml_decl(const xmlChar *str, size_t *lenp,
11041104
if (xmlStrncmp(p, (xmlChar *) "'yes'", 5) == 0 ||
11051105
xmlStrncmp(p, (xmlChar *) "\"yes\"", 5) == 0)
11061106
{
1107-
*standalone = 1;
1107+
if (standalone)
1108+
*standalone = 1;
11081109
p += 5;
11091110
}
11101111
else if (xmlStrncmp(p, (xmlChar *) "'no'", 4) == 0 ||
11111112
xmlStrncmp(p, (xmlChar *) "\"no\"", 4) == 0)
11121113
{
1113-
*standalone = 0;
1114+
if (standalone)
1115+
*standalone = 0;
11141116
p += 4;
11151117
}
11161118
else
@@ -1254,8 +1256,8 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace,
12541256
{
12551257
int res_code;
12561258
size_t count;
1257-
xmlChar *version = NULL;
1258-
int standalone = -1;
1259+
xmlChar *version;
1260+
int standalone;
12591261

12601262
res_code = parse_xml_decl(utf8string,
12611263
&count, &version, NULL, &standalone);

0 commit comments

Comments
 (0)