summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorJ. Rassi <rassi@10gen.com>2016-06-02 17:26:56 -0400
committerJ. Rassi <rassi@10gen.com>2016-06-03 13:28:17 -0400
commit7a191accbe3c13a276d7b886b9047e7acedf9be8 (patch)
treeeadecf61cfda81d15bc32f51a48582b675601ce8 /src/mongo/db/catalog
parentb5c5015d1ea0a10a25e31de20bd131a0d81c1a6e (diff)
downloadmongo-7a191accbe3c13a276d7b886b9047e7acedf9be8.tar.gz
SERVER-24380 Fix null deref. with coll/index having "simple" collation
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/database.cpp12
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp12
2 files changed, 21 insertions, 3 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index 26eb99c0a9c..afc511accd8 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -630,8 +630,16 @@ Status userCreateNS(OperationContext* txn,
return collator.getStatus();
}
- collectionOptions.collation =
- CollationSerializer::specToBSON(collator.getValue()->getSpec());
+ // If the collator factory returned a non-null collator, set the collation option to the
+ // result of serializing the collator's spec back into BSON. We do this in order to fill in
+ // all options that the user omitted.
+ //
+ // If the collator factory returned a null collator (representing the "simple" collation),
+ // we can't use the collation serializer. In this case, we simply set the collation option
+ // to the original user BSON.
+ collectionOptions.collation = collator.getValue()
+ ? CollationSerializer::specToBSON(collator.getValue()->getSpec())
+ : collectionOptions.collation;
}
status =
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index b1ed77750ed..9ebbaea256a 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -1315,7 +1315,17 @@ StatusWith<BSONObj> IndexCatalog::_fixIndexSpec(OperationContext* txn,
return collator.getStatus();
}
- b.append("collation", CollationSerializer::specToBSON(collator.getValue()->getSpec()));
+ // If the collator factory returned a non-null collator, set the collation option to the
+ // result of serializing the collator's spec back into BSON. We do this in order to fill in
+ // all options that the user omitted.
+ //
+ // If the collator factory returned a null collator (representing the "simple" collation),
+ // we can't use the collation serializer. In this case, we simply set the collation option
+ // to the original user BSON.
+ b.append("collation",
+ collator.getValue()
+ ? CollationSerializer::specToBSON(collator.getValue()->getSpec())
+ : collationElt.Obj());
} else if (collection->getDefaultCollator()) {
// The user did not specify an explicit collation for this index and the collection has a
// default collator. In this case, the index inherits the collection default.