[SERVER-1485] server crashes when creating a database with strange name Created: 25/Jul/10  Updated: 10/Dec/14  Resolved: 13/Jun/14

Status: Closed
Project: Core Server
Component/s: Security, Stability
Affects Version/s: 1.5.5
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Vlasta Neubauer Assignee: Matt Kangas
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongod 1.5.5 /64bit, Windows 7/64bit, PHP 5.3.2, PHP Mongo ext. 1.0.8


Operating System: Windows
Participants:

 Description   

when creating (writing to) a database named "aaa:" (double colon in name) database "aaa_" was created instead and the server shut down

from server console:
[initandlisten] Sun Jul 25 18:54:46 connection accepted from 127.0.0.1:52368 #8
[conn8] Sun Jul 25 18:54:46 Create/OpenFile failed /data/db/aaa_.ns 0
[conn8] Sun Jul 25 18:54:46 admin couldn't open file /data/db/aaa_.ns terminating
Sun Jul 25 18:54:46 dbexit:
[conn8] Sun Jul 25 18:54:46 shutdown: going to close listening sockets...
[conn8] Sun Jul 25 18:54:46 going to close listening socket: 172
[conn8] Sun Jul 25 18:54:46 going to close listening socket: 176
[initandlisten] Sun Jul 25 18:54:46 Listener: accept() returns -1 errno:10038 Do
šlo k pokusu o operaci s n??ím, co není soket. (Tried to use something, what is not a socket)

[conn8] Sun Jul 25 18:54:46 going to close listening socket: 188
[conn8] Sun Jul 25 18:54:46 going to close listening socket: 192
[conn8] Sun Jul 25 18:54:46 shutdown: going to flush oplog...
[conn8] Sun Jul 25 18:54:46 shutdown: going to close sockets...
[conn8] Sun Jul 25 18:54:46 shutdown: waiting for fs preallocator...
[conn8] Sun Jul 25 18:54:46 shutdown: closing all files...
Sun Jul 25 18:54:46 closeAllFiles() finished
Sun Jul 25 18:54:46 dbexit: really exiting now
ERROR: Client::~Client _context should be NULL: conn



 Comments   
Comment by Matt Kangas [ 13/Jun/14 ]

jstest:

var testdb = db.getSiblingDB('aaa:')
var t = testdb.db_server1485
t.insert({a:1})
testdb.stats()
db.getSiblingDB("aaa:").dropDatabase()

Result on Windows 2008 server (windows-64 build, 2.7.2-pre-).

2014-06-13T23:03:52.326+0100 Error: [aaa:] is not a valid database name
    at Mongo.getDB (src/mongo/shell/mongo.js:41:12)
    at DB.getSiblingDB (src/mongo/shell/db.js:20:28)
    at Z:\master\db_server1485.js:3:17 at src/mongo/shell/mongo.js:41
failed to load: Z:\master\db_server1485.js

And again in Python to confirm that it is the server rejecting the invalid name:

from pymongo import MongoClient
from pprint import pprint
 
client = MongoClient('localhost', 27999)
 
testdb = client['aaa::']
t = testdb.db_server1485
t.insert( {"a":1} )
 
pprint( testdb.command("dbstats") )
client.drop_database('aaa::')

Result on same windows-64 instance

$ /cygdrive/c/Python27/python db_server1485.py
Traceback (most recent call last):
  File "db_server1485.py", line 10, in <module>
    t.insert( {"a":1} )
  File "C:\Python27\lib\site-packages\pymongo\collection.py", line 362, in insert
    self.database.connection)
  File "C:\Python27\lib\site-packages\pymongo\message.py", line 248, in _do_batched_insert
    client._send_message(_insert_message(EMPTY.join(data), safe), safe)
  File "C:\Python27\lib\site-packages\pymongo\mongo_client.py", line 969, in _send_message
    rv = self.__check_response_to_last_error(response)
  File "C:\Python27\lib\site-packages\pymongo\mongo_client.py", line 884, in __check_response_to_last_error
    response = helpers._unpack_response(response)
  File "C:\Python27\lib\site-packages\pymongo\helpers.py", line 100, in _unpack_response
    error_object["$err"])
pymongo.errors.OperationFailure: database error: Invalid ns [aaa::.$cmd]

Comment by Andreas Nilsson [ 11/Jun/14 ]

gianfranco can you check if this is still present in 2.6 (regardless of the shell).

Comment by Eliot Horowitz (Inactive) [ 20/Aug/13 ]

shell doesn't count

Comment by Gianfranco Palumbo [ 20/Aug/13 ]

Shell now prevents this in 2.4.4 (tested on Windows 64bit)

> use db:
Tue Aug 20 14:32:34.456 JavaScript execution failed: Error: [db:] is not a valid database name at src/mongo/shell/mongo.js:L40

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