summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/object_check_test.cpp
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@mongodb.com>2021-06-28 22:42:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-04 17:15:32 +0000
commit1746aef0112ada4c01fc3c17d482e68eed1ae3ee (patch)
tree70dad84ae9faa46ccafb80a33136b8ee80f8b559 /src/mongo/rpc/object_check_test.cpp
parent9ae4eb2650e5086058a88452f6a72efc5bd95766 (diff)
downloadmongo-1746aef0112ada4c01fc3c17d482e68eed1ae3ee.tar.gz
SERVER-50761 Crash the shell on invalid BSON errors on server responses from outgoing connections in
all of the jstestfuzz test suites. Combine a new shell parameter --crashOnInvalidBSONError with --objcheck in the shell for all jstestfuzz test suites. --objcheck in the shell turns on BSON validation on responses from outgoing connections to the server. --crashOnInvalidBSONError crashes the shell if that extra BSON validation encounters an error, and attempts to log the invalid BSON for debugging.
Diffstat (limited to 'src/mongo/rpc/object_check_test.cpp')
-rw-r--r--src/mongo/rpc/object_check_test.cpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/mongo/rpc/object_check_test.cpp b/src/mongo/rpc/object_check_test.cpp
index 52010604f53..7ecb0d0ed93 100644
--- a/src/mongo/rpc/object_check_test.cpp
+++ b/src/mongo/rpc/object_check_test.cpp
@@ -35,23 +35,22 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/server_options.h"
#include "mongo/rpc/object_check.h"
+#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/scopeguard.h"
namespace {
using namespace mongo;
+using std::begin;
+using std::end;
+using std::swap;
TEST(DataTypeValidated, BSONValidationEnabled) {
- using std::swap;
-
bool wasEnabled = serverGlobalParams.objcheck;
const auto setValidation = [&](bool enabled) { serverGlobalParams.objcheck = enabled; };
ON_BLOCK_EXIT([=] { setValidation(wasEnabled); });
- using std::begin;
- using std::end;
-
BSONObj valid = BSON("baz"
<< "bar"
<< "garply"
@@ -88,4 +87,39 @@ TEST(DataTypeValidated, BSONValidationEnabled) {
ASSERT_OK(cdrc.readAndAdvanceNoThrow(&v));
}
}
+
+DEATH_TEST(ObjectCheck, BSONValidationEnabledWithCrashOnError, "50761") {
+ bool objcheckValue = serverGlobalParams.objcheck;
+ serverGlobalParams.objcheck = true;
+ ON_BLOCK_EXIT([=] { serverGlobalParams.objcheck = objcheckValue; });
+
+ bool crashOnErrorValue = serverGlobalParams.crashOnInvalidBSONError;
+ serverGlobalParams.crashOnInvalidBSONError = true;
+ ON_BLOCK_EXIT([&] { serverGlobalParams.crashOnInvalidBSONError = crashOnErrorValue; });
+
+ BSONObj valid = BSON("baz"
+ << "bar"
+ << "garply"
+ << BSON("foo"
+ << "bar"));
+ char buf[1024] = {0};
+ std::copy(valid.objdata(), valid.objdata() + valid.objsize(), begin(buf));
+
+ {
+ // mess up the data
+ DataRangeCursor drc(begin(buf), end(buf));
+ // skip past size so we don't trip any sanity checks.
+ drc.advanceNoThrow(4).transitional_ignore(); // skip size
+ while (drc.writeAndAdvanceNoThrow(0xFF).isOK())
+ ;
+ }
+
+ {
+ Validated<BSONObj> v;
+ ConstDataRangeCursor cdrc(begin(buf), end(buf));
+ // Crashes because of invalid BSON
+ cdrc.readAndAdvanceNoThrow(&v).ignore();
+ }
+}
+
} // namespace