It looks as if the mongos can create databases with invalid names, leading to subsequent problems draining the shard with the invalid db name (see https://groups.google.com/group/mongodb-user/browse_thread/thread/7186e51d5a31bcd2?pli=1).
Here's a reproduction case for creating an entry in config.databases with an invalid name:
mongos> config=db.getSiblingDB("config")
config
mongos> config.databases.find()
mongos> foo=db.getSiblingDB("foo ");
foo
mongos> foo.c.insert(
);
invalid db name: foo .c
mongos> config.databases.find()
mongos> db.adminCommand(
{ listDatabases : 1 });
{
"databases" : [
{
"name" : "test",
"sizeOnDisk" : 218103808,
"empty" : false,
"shards" :
},
{ "name" : "config", "empty" : false, "sizeOnDisk" : 201326592 } ],
"totalSize" : 218103808,
"totalSizeMb" : 208,
"ok" : 1
}