From 8074b722f0e13a3aad37460f40891660258efece Mon Sep 17 00:00:00 2001 From: Eli Fidler Date: Tue, 31 May 2016 11:54:58 -0400 Subject: [PATCH] avoid reference to null pointer and member access within null pointer UBSAN gave issues with the typeless Schema: runtime error: reference binding to null pointer of type 'rapidjson::GenericSchemaDocument, rapidjson::MemoryPoolAllocator >, rapidjson::CrtAllocator>' and runtime error: member access within null pointer of type 'AllocatorType' (aka 'rapidjson::CrtAllocator') --- include/rapidjson/schema.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index 0a8bb7c..80812f0 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -413,9 +413,11 @@ public: } } - AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document); - AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document); - AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document); + if (schemaDocument) { + AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document); + AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document); + AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document); + } if (const ValueType* v = GetMember(value, GetNotString())) { schemaDocument->CreateSchema(¬_, p.Append(GetNotString(), allocator_), *v, document); @@ -578,7 +580,9 @@ public: } ~Schema() { - allocator_->Free(enum_); + if (allocator_) { + allocator_->Free(enum_); + } if (properties_) { for (SizeType i = 0; i < propertyCount_; i++) properties_[i].~Property();