[SERVER-6559] db.runCommand with renameCollection causes mongod to crash Created: 23/Jul/12  Updated: 11/Jul/16  Resolved: 07/Aug/12

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.2.0-rc0
Fix Version/s: 2.2.0-rc1

Type: Bug Priority: Minor - P4
Reporter: Kim Miller Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

RHEL 6.1 64 bit


Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Trying to drop a collection named with periods and underscores, which fails. Tried to rename is using renameCollection, to then drop it. The runCommand/renameCollection causes mongod to crash:

[kmiller@walnut badger]$ start-datastore
forked process: 14574
all output going to: /home/kmiller/datastore/mongod.log
child process started successfully, parent exiting
[kmiller@walnut badger]$ mongo localhost:27006/kmiller --verbose
MongoDB shell version: 2.2.0-rc0
Mon Jul 23 14:39:54 versionCmpTest passed
Mon Jul 23 14:39:54 versionArrayTest passed
connecting to: localhost:27006/kmiller
Mon Jul 23 14:39:54 creating new connection to:localhost:27006
Mon Jul 23 14:39:54 BackgroundJob starting: ConnectBG
Mon Jul 23 14:39:54 connected connection!
MongoDB(SECONDARY) 57.4.26.83:27006/kmiller> db.distribution.20120524_1342.drop()
Mon Jul 23 14:40:10 SyntaxError: missing ; before statement (shell):1
MongoDB(PRIMARY) 57.4.26.83:27006/kmiller> use admin
switched to db admin
MongoDB(PRIMARY) 57.4.26.83:27006/admin> db.runCommand(

{renameCollection: "distribution.20120524_1342", to: "deleteme"}

)
Mon Jul 23 14:40:18 SocketException: remote: 127.0.0.1:27006 error: 9001 socket exception [0] server [127.0.0.1:27006]
Mon Jul 23 14:40:18 DBClientCursor::init call() failed
Mon Jul 23 14:40:18 query failed : admin.$cmd

{ renameCollection: "distribution.20120524_1342", to: "deleteme" }

to: localhost:27006
Mon Jul 23 14:40:18 Error: error doing query: failed src/mongo/shell/collection.js:155
Mon Jul 23 14:40:18 trying reconnect to localhost:27006
Mon Jul 23 14:40:18 BackgroundJob starting: ConnectBG
Mon Jul 23 14:40:18 reconnect localhost:27006 failed couldn't connect to server localhost:27006
> exit
bye
[kmiller@walnut badger]$ ps -ef|grep kmiller|grep mongod
kmiller 14660 13972 0 14:40 pts/6 00:00:00 grep mongod

Noticed this happened in 2.1.2 as well, but thought it might be fixed in 2.2.0-rc0. It isn't urgent to delete the collection and I know this is just a release candidate, but noticed the problem and thought I would mention it.

Rgds/Kim



 Comments   
Comment by auto [ 07/Aug/12 ]

Author:

{u'date': u'2012-08-07T08:36:21-07:00', u'email': u'tad@10gen.com', u'name': u'Tad Marshall'}

Message: SERVER-6559 do not segfault parsing collection name

Rework two lines of code to not crash on missing periods in
namespace names being checked for correctness.
Branch: master
https://github.com/mongodb/mongo/commit/aec02b62d192a56b647e6f28afbe5bfdec9b2e92

Comment by Tad Marshall [ 23/Jul/12 ]

Confirmed: passing a "to" collection name that does not include a period leads to segfault.

mongo/src/mongo/db/namespacestring.h lines 115 to 118 (annotated):

static bool validCollectionName(const char* dbcoll){
    const char *c = strchr( dbcoll, '.' ) + 1;    // strchr() returns zero if character not found, so 'c' is set to 1
    return normal(dbcoll) && c && *c;             // segfault reading from address 1
}

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