summaryrefslogtreecommitdiff
path: root/src/mongo/db/views
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2018-09-04 17:01:57 -0400
committerJustin Seyster <justin.seyster@mongodb.com>2018-09-07 14:51:31 -0400
commitec132343b7e7225e36575f173c242b383f505eb2 (patch)
tree3f75285bc6733af1364e7564518d8e6ca594bcb6 /src/mongo/db/views
parent53e841861042a5fab55bfdf55021f8a7154fdb6d (diff)
downloadmongo-ec132343b7e7225e36575f173c242b383f505eb2.tar.gz
SERVER-36859 Validate dbname in DurableViewCatalogImpl::iterate().
If the DatabaseImpl constructor (which calls DurableViewCatalogImpl::iterate()) throws an exception, the partially constructed DatabaseImpl trips an invariant as it gets destroyed during exception unwinding. This change makes sure that DurableViewCatalogImpl::iterate() properly validates the 'viewOn' namespace, so that it doesn't throw an exception when getting parsed as a NamespaceString.
Diffstat (limited to 'src/mongo/db/views')
-rw-r--r--src/mongo/db/views/durable_view_catalog.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp
index 3284b303d40..39ef3b598cc 100644
--- a/src/mongo/db/views/durable_view_catalog.cpp
+++ b/src/mongo/db/views/durable_view_catalog.cpp
@@ -95,12 +95,13 @@ Status DurableViewCatalogImpl::iterate(OperationContext* opCtx, Callback callbac
}
const auto viewName = viewDef["_id"].str();
- const auto collectionNameIsValid = NamespaceString::validCollectionComponent(viewName);
- valid &= collectionNameIsValid;
+ const auto viewNameIsValid = NamespaceString::validCollectionComponent(viewName) &&
+ NamespaceString::validDBName(nsToDatabaseSubstring(viewName));
+ valid &= viewNameIsValid;
// Only perform validation via NamespaceString if the collection name has been determined to
// be valid. If not valid then the NamespaceString constructor will uassert.
- if (collectionNameIsValid) {
+ if (viewNameIsValid) {
NamespaceString viewNss(viewName);
valid &= viewNss.isValid() && viewNss.db() == _db->name();
}