diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-03-06 22:20:44 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-03-06 22:20:44 -0500 |
commit | cc206ecdf653b074d0e3ad1b639e1ce782888219 (patch) | |
tree | 648360cefc3e4a1081a8c0fe248f4f6ac7830637 | |
parent | 084eb0c7f248eb56dc42dff528e1e6d32e4e6dff (diff) | |
download | mongo-cc206ecdf653b074d0e3ad1b639e1ce782888219.tar.gz |
manually cherry-pick for SERVER-706
-rw-r--r-- | db/jsobj.cpp | 12 | ||||
-rw-r--r-- | dbtests/jsobjtests.cpp | 33 |
2 files changed, 11 insertions, 34 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 17cdf4db533..400f2c7a348 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -608,11 +608,15 @@ namespace mongo { case DBRef: case Code: case Symbol: - case String: - massert( "Invalid dbref/code/string/symbol size", - valuestrsize() > 0 && - valuestrsize() - 1 == strnlen( valuestr(), valuestrsize() ) ); + case String: { + int x = valuestrsize(); + if ( x > 0 && valuestr()[x-1] == 0 ) + return; + stringstream buf; + buf << "Invalid dbref/code/string/symbol size: " << x; + massert( buf.str() , 0 ); break; + } case CodeWScope: { int totalSize = *( int * )( value() ); massert( "Invalid CodeWScope size", totalSize >= 8 ); diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index 8ad2154a8cb..212377f0105 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -339,8 +339,9 @@ namespace JsobjTests { } BSONObj invalid() const { BSONObj ret = valid(); - set( ret, 0, get( ret, 0 ) + 1 ); - set( ret, 7, get( ret, 7 ) + 1 ); + ASSERT_EQUALS( ret.firstElement().valuestr()[0] , 'b' ); + ASSERT_EQUALS( ret.firstElement().valuestr()[1] , 0 ); + ((char*)ret.firstElement().valuestr())[1] = 1; return ret.copy(); } }; @@ -391,32 +392,6 @@ namespace JsobjTests { }; }; - class WrongSymbolSize : public Base { - BSONObj valid() const { - return fromjson( "{\"a\":\"b\"}" ); - } - BSONObj invalid() const { - BSONObj ret = valid(); - set( ret, 4, Symbol ); - set( ret, 0, get( ret, 0 ) + 1 ); - set( ret, 7, get( ret, 7 ) + 1 ); - return ret.copy(); - } - }; - - class WrongCodeSize : public Base { - BSONObj valid() const { - return fromjson( "{\"a\":\"b\"}" ); - } - BSONObj invalid() const { - BSONObj ret = valid(); - set( ret, 4, Code ); - set( ret, 0, get( ret, 0 ) + 1 ); - set( ret, 7, get( ret, 7 ) + 1 ); - return ret.copy(); - } - }; - class NoFieldNameEnd : public Base { BSONObj valid() const { return fromjson( "{\"a\":1}" ); @@ -1248,8 +1223,6 @@ namespace JsobjTests { add< BSONObjTests::Validation::NegativeStringSize >(); add< BSONObjTests::Validation::WrongSubobjectSize >(); add< BSONObjTests::Validation::WrongDbrefNsSize >(); - add< BSONObjTests::Validation::WrongSymbolSize >(); - add< BSONObjTests::Validation::WrongCodeSize >(); add< BSONObjTests::Validation::NoFieldNameEnd >(); add< BSONObjTests::Validation::BadRegex >(); add< BSONObjTests::Validation::BadRegexOptions >(); |