diff options
author | Matt Kneiser <matt.kneiser@mongodb.com> | 2022-01-13 00:22:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-13 06:29:13 +0000 |
commit | fd6b2a875f8942a4ba7fea916b4c52a913e14f49 (patch) | |
tree | 8e18dd580f8d03a42f27ed7af357cae38a2ff745 /src/mongo/db/timeseries | |
parent | 47c77eedf3bb0b4305f2ca1d8e362b27d599008f (diff) | |
download | mongo-fd6b2a875f8942a4ba7fea916b4c52a913e14f49.tar.gz |
SERVER-27209 Eliminate dangerous BSONElement string extraction methods
- Fix: Change return type of BSONObj::getStringField to include size
(StringData vs. char*). A char* only contains the data with an ending NULL
termination. Whereas a StringData contains data + size so caller knows how
to interpret data if there are embedded NULLs.
- Cleanup: Remove old tag - CachedSizeTag - that disambiguated BSONElement ctors.
A dangling reference to 'maxLen' in a comment led me to this historical issue.
$ git log -S'maxLen' -- src/mongo/bson/bsonelement.h
commit 0d38ef5
Author: Mathias Stearn mathias@10gen.com
Date: Tue Dec 19 14:23:08 2017 -0500
SERVER-32302 Compute BSONElement sizes eagerly
- Test: Add tests for NULL bytes being returned by getStringField
- $ ninja -j400 +bson_obj_test
- Cleanup: Move BSONElement::valuestr() from public to private
- Cleanup: Remove BSONElement::valuestrsafe()
- Cleanup: Remove all external callers of valuestr/valuestrsafe and cleanup
their callsites with better alternatives.
- Cleanup: Make multi-line BSONElement & BSONObj public API comments
conform to style guidelines
- Nit: Fix spelling in a comment
Diffstat (limited to 'src/mongo/db/timeseries')
-rw-r--r-- | src/mongo/db/timeseries/bucket_catalog.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/timeseries/flat_bson.cpp | 2 |
2 files changed, 2 insertions, 3 deletions
diff --git a/src/mongo/db/timeseries/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog.cpp index 3c0c3b37ec7..9b06cdbdc33 100644 --- a/src/mongo/db/timeseries/bucket_catalog.cpp +++ b/src/mongo/db/timeseries/bucket_catalog.cpp @@ -88,8 +88,7 @@ void normalizeObject(BSONObjBuilder* builder, const BSONObj& obj) { BSONElement element() const { return BSONElement(fieldName.rawData() - 1, // Include type byte before field name fieldName.size() + 1, // Include null terminator after field name - totalSize, - BSONElement::CachedSizeTag{}); + totalSize); } bool operator<(const Field& rhs) const { return fieldName < rhs.fieldName; diff --git a/src/mongo/db/timeseries/flat_bson.cpp b/src/mongo/db/timeseries/flat_bson.cpp index 595dde0942f..e5b15133b1e 100644 --- a/src/mongo/db/timeseries/flat_bson.cpp +++ b/src/mongo/db/timeseries/flat_bson.cpp @@ -673,7 +673,7 @@ void FlatBSON<Derived, Element, Value>::_setTypeArray( } BSONElement BSONElementValue::get() const { - return BSONElement(_buffer.get(), 1, _size, BSONElement::CachedSizeTag{}); + return BSONElement(_buffer.get(), 1, _size); } void BSONElementValue::set(const BSONElement& elem) { |