From 9f01a92f4c0aeae86da650e3eaa50aa63adca2a5 Mon Sep 17 00:00:00 2001 From: alexvins Date: Mon, 10 Mar 2014 15:58:13 +0000 Subject: [PATCH] fix crash in jsonschema in case of invalid typename --- lib/JsonDetail.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/JsonDetail.cpp b/lib/JsonDetail.cpp index c788c4cd4..cb020c2f0 100644 --- a/lib/JsonDetail.cpp +++ b/lib/JsonDetail.cpp @@ -594,8 +594,15 @@ namespace } std::string typeCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data) - { - JsonNode::JsonType type = stringToType.find(schema.String())->second; + { + const auto typeName = schema.String(); + auto it = stringToType.find(typeName); + if(it == stringToType.end()) + { + return validator.makeErrorMessage("Unknown type in schema:" + typeName); + } + + JsonNode::JsonType type = it->second; if(type != data.getType() && data.getType() != JsonNode::DATA_NULL) return validator.makeErrorMessage("Type mismatch! Expected " + schema.String()); return "";