[SERVER-16751] Use prefix matching to detect system namespaces, not substring matching Created: 07/Jan/15  Updated: 08/Jan/15  Resolved: 08/Jan/15

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 2.8.0-rc4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kevin Pulo Assignee: Matt Kangas
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-4558 namespace validation on insert uses s... Backlog
Related
related to SERVER-8814 Inserts into any namespace ending in ... Closed
Operating System: ALL
Participants:

 Description   

There are places in the code where we do

if ( strstr(ns, ".system.") )

or

if ( ns.find(".system.") != string::npos )

to detect system namespaces. Such substring matching is incorrect, since it returns true for namespaces like "db.foo.system.bar", which are not usually considered system namespaces. Matching should be prefix-based, as is now done for writes, for example.

This is along the same lines as SERVER-4558 and SERVER-8814, which refer to specific instances of this.

The cases that seem to be present currently are:

$ ag 'strstr *\(.* *"\.system\."'
src/mongo/db/query/get_executor.cpp
571:            if (strstr(ns, ".system.")) {
 
$ ag '\.find *\( *"\.system\."'
src/mongo/db/query/get_executor.cpp
145:                          || (string::npos != ns.find(".system."))
 
src/mongo/db/ops/insert.cpp
188:        if ( coll.find( ".system." ) != string::npos ) {
 
src/mongo/s/commands_admin.cpp
526:                if ( ns.find( ".system." ) != string::npos ) {

This ticket is to request that these occurrences in the code be updated to use prefix matches, not substring matches. Specifically:

Probably somewhere there should be single isSystemNamespace()/isSystemCollection() function(s) for doing this detection consistently.



 Comments   
Comment by Matt Kangas [ 08/Jan/15 ]

Resolving as duplicate of SERVER-4558. Content copied to that ticket

Generated at Thu Feb 08 03:42:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.