From 6a20bb04e9d4a78b0f8516fbda4f60b34f389699 Mon Sep 17 00:00:00 2001 From: ravinsp <33562092+ravinsp@users.noreply.github.com> Date: Wed, 22 Jul 2020 15:10:31 +0530 Subject: [PATCH] Improved bson message field validations. --- src/msg/bson/usrmsg_bson.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/msg/bson/usrmsg_bson.cpp b/src/msg/bson/usrmsg_bson.cpp index 678bec55..10787224 100644 --- a/src/msg/bson/usrmsg_bson.cpp +++ b/src/msg/bson/usrmsg_bson.cpp @@ -134,7 +134,7 @@ namespace msg::usrmsg::bson return -1; } - if (!d[FLD_TYPE].is_string()) + if (!d.contains(FLD_TYPE) || !d[FLD_TYPE].is_string()) { LOG_DBG << "User bson message 'type' missing or invalid."; return -1; @@ -166,9 +166,9 @@ namespace msg::usrmsg::bson */ int extract_read_request(std::string &extracted_content, const jsoncons::ojson &d) { - if (!d[msg::usrmsg::FLD_CONTENT].is_byte_string_view()) + if (!d.contains(msg::usrmsg::FLD_CONTENT) || !d[msg::usrmsg::FLD_CONTENT].is_byte_string_view()) { - LOG_DBG << "Read request 'content' fields missing or invalid."; + LOG_DBG << "Read request 'content' field missing or invalid."; return -1; } @@ -194,7 +194,8 @@ namespace msg::usrmsg::bson int extract_signed_input_container( std::string &extracted_input_container, std::string &extracted_sig, const jsoncons::ojson &d) { - if (!d[msg::usrmsg::FLD_INPUT_CONTAINER].is_byte_string_view() || !d[msg::usrmsg::FLD_SIG].is_byte_string_view()) + if (!d.contains(msg::usrmsg::FLD_INPUT_CONTAINER) || !d.contains(msg::usrmsg::FLD_SIG) || + !d[msg::usrmsg::FLD_INPUT_CONTAINER].is_byte_string_view() || !d[msg::usrmsg::FLD_SIG].is_byte_string_view()) { LOG_DBG << "User signed input required fields missing or invalid."; return -1; @@ -235,7 +236,8 @@ namespace msg::usrmsg::bson return -1; } - if (!d[msg::usrmsg::FLD_INPUT].is_byte_string_view() || !d[msg::usrmsg::FLD_NONCE].is_string() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].is_uint64()) + if (!d.contains(msg::usrmsg::FLD_INPUT) || !d.contains(msg::usrmsg::FLD_NONCE) || !d.contains(msg::usrmsg::FLD_MAX_LCL_SEQ) || + !d[msg::usrmsg::FLD_INPUT].is_byte_string_view() || !d[msg::usrmsg::FLD_NONCE].is_string() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].is_uint64()) { LOG_DBG << "User input container required fields missing or invalid."; return -1;