Fix crash in schema parser

Closes #71.
Includes testcase.
This commit is contained in:
Sandro Santilli 2015-04-14 11:26:05 +02:00
parent fc409ca842
commit e5605e9292
4 changed files with 11 additions and 8 deletions

View File

@ -402,7 +402,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xml_doc = xmlReadMemory(xml_ptr, xml_size, NULL, NULL, 0);
if ( ! xml_doc )
{
xmlCleanupParser();
pcwarn("unable to parse schema XML");
return PC_FAILURE;
}
@ -417,7 +416,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
if( ! xpath_ctx )
{
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pcwarn("unable to create new XPath context to read schema XML");
return PC_FAILURE;
}
@ -432,7 +430,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
{
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pcwarn("unable to evaluate xpath expression \"%s\" against schema XML", xpath_str);
return PC_FAILURE;
}
@ -512,7 +509,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xmlXPathFreeObject(xpath_obj);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pc_schema_free(s);
pcwarn("schema dimension at position \"%d\" is declared twice", d->position + 1, ndims);
return PC_FAILURE;
@ -532,7 +528,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xmlXPathFreeObject(xpath_obj);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pc_schema_free(s);
pcwarn("schema dimension states position \"%d\", but number of XML dimensions is \"%d\"", d->position + 1, ndims);
return PC_FAILURE;
@ -554,7 +549,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
{
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pcwarn("unable to evaluate xpath expression \"%s\" against schema XML", xpath_metadata_str);
return PC_FAILURE;
}
@ -594,7 +588,6 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
return PC_SUCCESS;
}

View File

@ -24,7 +24,7 @@ DATA_built = \
$(EXTENSION)--$(EXTVERSION).sql \
$(UPGRADES)
REGRESS = pointcloud pointcloud_columns
REGRESS = pointcloud pointcloud_columns schema
ifneq ($(GHT_LDFLAGS),)
REGRESS += pointcloud-ght

View File

@ -0,0 +1,8 @@
-- See https://github.com/pgpointcloud/pointcloud/issues/71
select '#71', PC_SchemaIsValid('<xml/>'::xml::text);
WARNING: unable to evaluate xpath expression "/pc:PointCloudSchema/pc:dimension" against schema XML
?column? | pc_schemaisvalid
----------+------------------
#71 | f
(1 row)

2
pgsql/sql/schema.sql Normal file
View File

@ -0,0 +1,2 @@
-- See https://github.com/pgpointcloud/pointcloud/issues/71
select '#71', PC_SchemaIsValid('<xml/>'::xml::text);