diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-05-30 16:50:03 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-06-13 17:15:27 -0400 |
commit | 52c36ee17b8f58d71b074fe2cf34ca0b3a744f5c (patch) | |
tree | a5e2e340db71fc2ea8d6a3b64cd3a57d61684a2d /src/mongo/util | |
parent | bf2ddb54895019b59495fb5ea96413b64b45aa7f (diff) | |
download | mongo-52c36ee17b8f58d71b074fe2cf34ca0b3a744f5c.tar.gz |
SERVER-29461 check for duplicate fields when serializing OP_MSG
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/net/op_msg.cpp | 16 | ||||
-rw-r--r-- | src/mongo/util/net/op_msg.h | 7 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/mongo/util/net/op_msg.cpp b/src/mongo/util/net/op_msg.cpp index 72b27e7482d..5d451af15f0 100644 --- a/src/mongo/util/net/op_msg.cpp +++ b/src/mongo/util/net/op_msg.cpp @@ -32,12 +32,13 @@ #include "mongo/util/net/op_msg.h" +#include <set> + #include "mongo/db/bson/dotted_path_support.h" #include "mongo/rpc/object_check.h" #include "mongo/util/bufreader.h" #include "mongo/util/hex.h" #include "mongo/util/log.h" -#include "mongo/util/string_map.h" namespace mongo { namespace { @@ -183,7 +184,20 @@ BSONObjBuilder OpMsgBuilder::resumeBody() { return BSONObjBuilder(BSONObjBuilder::ResumeBuildingTag(), _buf, _bodyStart); } +AtomicBool OpMsgBuilder::disableDupeFieldCheck_forTest{false}; + Message OpMsgBuilder::finish() { + if (kDebugBuild && !disableDupeFieldCheck_forTest.load()) { + std::set<StringData> seenFields; + for (auto elem : resumeBody().asTempObj()) { + if (!(seenFields.insert(elem.fieldNameStringData()).second)) { + severe() << "OP_MSG with duplicate field '" << elem.fieldNameStringData() + << "' : " << redact(resumeBody().asTempObj()); + fassert(40474, false); + } + } + } + invariant(_state == kBody); invariant(_bodyStart); invariant(!_openBuilder); diff --git a/src/mongo/util/net/op_msg.h b/src/mongo/util/net/op_msg.h index 98b04c1bc20..dc8037146be 100644 --- a/src/mongo/util/net/op_msg.h +++ b/src/mongo/util/net/op_msg.h @@ -210,6 +210,13 @@ public: _openBuilder = false; } + /** + * Set to true in tests that need to be able to generate duplicate top-level fields to see how + * the server handles them. Is false by default, although the check only happens in debug + * builds. + */ + static AtomicBool disableDupeFieldCheck_forTest; + private: friend class DocSequenceBuilder; |