summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2016-03-11 16:24:36 -0500
committersamantharitter <samantha.ritter@10gen.com>2016-03-17 11:21:41 -0400
commit31701cb45e15c8c6cd7f89232c04893aad7565fe (patch)
treee7dd82ddbe919751903ed8ecff0917b68a74a4ae
parenta8412488599ba9def9dea29505ea69323ba6e1fc (diff)
downloadmongo-31701cb45e15c8c6cd7f89232c04893aad7565fe.tar.gz
SERVER-22701 Make replace modifier timestamp handling endian-safe
-rw-r--r--src/mongo/db/ops/SConscript1
-rw-r--r--src/mongo/db/ops/modifier_object_replace.cpp10
2 files changed, 7 insertions, 4 deletions
diff --git a/src/mongo/db/ops/SConscript b/src/mongo/db/ops/SConscript
index de1bd249580..779bd57740c 100644
--- a/src/mongo/db/ops/SConscript
+++ b/src/mongo/db/ops/SConscript
@@ -69,6 +69,7 @@ env.Library(
'modifier_unset.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/matcher/expressions',
'$BUILD_DIR/mongo/db/global_timestamp',
'update_common',
diff --git a/src/mongo/db/ops/modifier_object_replace.cpp b/src/mongo/db/ops/modifier_object_replace.cpp
index 700f111e5b3..64bec6283d7 100644
--- a/src/mongo/db/ops/modifier_object_replace.cpp
+++ b/src/mongo/db/ops/modifier_object_replace.cpp
@@ -28,6 +28,7 @@
#include "mongo/db/ops/modifier_object_replace.h"
+#include "mongo/base/data_view.h"
#include "mongo/base/error_codes.h"
#include "mongo/bson/mutable/document.h"
#include "mongo/db/global_timestamp.h"
@@ -48,13 +49,14 @@ Status fixupTimestamps(const BSONObj& obj) {
// Skip _id field -- we do not replace it
if (e.type() == bsonTimestamp && e.fieldNameStringData() != idFieldName) {
- // TODO(emilkie): This is not endian-safe.
- unsigned long long& timestamp =
- *(reinterpret_cast<unsigned long long*>(const_cast<char*>(e.value())));
+ auto timestampView = DataView(const_cast<char*>(e.value()));
+
+ // We don't need to do an endian-safe read here, because 0 is 0 either way.
+ unsigned long long timestamp = timestampView.read<unsigned long long>();
if (timestamp == 0) {
// performance note, this locks a mutex:
Timestamp ts(getNextGlobalTimestamp());
- timestamp = ts.asULL();
+ timestampView.write(tagLittleEndian(ts.asULL()));
}
}
}