0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

try to prevent segfault on corrupt data SERVER-1724

This commit is contained in:
Eliot Horowitz 2010-09-03 11:59:13 -04:00
parent 2e8bb745dc
commit 1c0d685f9a
2 changed files with 4 additions and 1 deletions

View File

@ -261,7 +261,7 @@ namespace mongo {
case Symbol:
case mongo::String: {
int x = valuestrsize();
if ( x > 0 && valuestr()[x-1] == 0 )
if ( x > 0 && x < BSONObjMaxSize && valuestr()[x-1] == 0 )
return;
StringBuilder buf;
buf << "Invalid dbref/code/string/symbol size: " << x << " strnlen:" << mongo::strnlen( valuestr() , x );

View File

@ -27,6 +27,8 @@ namespace mongo {
typedef set< BSONElement, BSONElementCmpWithoutField > BSONElementSet;
const int BSONObjMaxSize = 32 * 1024 * 1024;
/**
C++ representation of a "BSON" object -- that is, an extended JSON-style
object in a binary representation.
@ -67,6 +69,7 @@ namespace mongo {
*/
class BSONObj {
public:
/** Construct a BSONObj from data in the proper format.
@param ifree true if the BSONObj should free() the msgdata when
it destructs.