schemas: Fix null-pointer-deref in xmlSchemaCheckCOSSTDerivedOK

Found by OSS-Fuzz.
This commit is contained in:
Nick Wellnhofer 2022-09-13 16:40:31 +02:00
parent f2392dc464
commit 1d4f5d24ac
4 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1,2 @@
./test/schemas/oss-fuzz-51295_0.xsd:2: element element: Schemas parser error : element decl. 'e': The element declaration 'e' defines a circular substitution group to element declaration 'e'.
./test/schemas/oss-fuzz-51295_0.xsd:2: element element: Schemas parser error : element decl. 'e': The element declaration 'e' defines a circular substitution group to element declaration 'e'.

View File

@ -0,0 +1 @@
<e/>

View File

@ -0,0 +1,4 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="e" substitutionGroup="e"/>
<xs:element name="t" substitutionGroup="e" type='xs:decimal'/>
</xs:schema>

View File

@ -13348,8 +13348,19 @@ xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl,
* declaration `resolved` to by the `actual value`
* of the substitutionGroup [attribute], if present"
*/
if (elemDecl->subtypes == NULL)
elemDecl->subtypes = substHead->subtypes;
if (elemDecl->subtypes == NULL) {
if (substHead->subtypes == NULL) {
/*
* This can happen with self-referencing substitution
* groups. The cycle will be detected later, but we have
* to set subtypes to avoid null-pointer dereferences.
*/
elemDecl->subtypes = xmlSchemaGetBuiltInType(
XML_SCHEMAS_ANYTYPE);
} else {
elemDecl->subtypes = substHead->subtypes;
}
}
}
}
/*