Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

make sure db doesn't crash with weird db.eval returns SERVER-159

  • Loading branch information...
commit 294f9e48733c03d3ee7f5960dc363b341a0983e3 1 parent 2d8e4fd
Eliot authored
11  jstests/eval9.js
@@ -6,3 +6,14 @@ for ( var i=0; i<a.length; i++ ){
6 6
     assert.eq( typeof( a[i] ) , typeof( ret ) , "type test" );
7 7
     assert.eq( a[i] , ret , "val test: " + typeof( a[i] ) );
8 8
 }
  9
+
  10
+db.eval9.drop();
  11
+db.eval9.save( { a : 17 } );
  12
+
  13
+assert.eq( 1 , db.eval( "return db.eval9.find().toArray()" ).length , "A" );
  14
+assert.eq( 17 , db.eval( "return db.eval9.find().toArray()" )[0].a , "B" );
  15
+
  16
+// just to make sure these things don't crash
  17
+assert( db.eval( "return db.eval9.find()" ) );
  18
+assert( db.eval( "return db.eval9" ) );
  19
+assert( db.eval( "return db" ) );
37  scripting/engine_spidermonkey.cpp
@@ -149,27 +149,30 @@ namespace mongo {
149 149
 
150 150
             BSONObjBuilder b;
151 151
 
152  
-            jsval theid = getProperty( o , "_id" );
153  
-            if ( ! JSVAL_IS_VOID( theid ) ){
154  
-                append( b , "_id" , theid );
155  
-            }
156  
-
157  
-            JSIdArray * properties = JS_Enumerate( _context , o );
158  
-            assert( properties );
  152
+            if ( ! appendSpecialDBObject( this , b , "value" , o ) ){
159 153
 
160  
-            for ( jsint i=0; i<properties->length; i++ ){
161  
-                jsid id = properties->vector[i];
162  
-                jsval nameval;
163  
-                assert( JS_IdToValue( _context ,id , &nameval ) );
164  
-                string name = toString( nameval );
165  
-                if ( name == "_id" )
166  
-                    continue;
  154
+                jsval theid = getProperty( o , "_id" );
  155
+                if ( ! JSVAL_IS_VOID( theid ) ){
  156
+                    append( b , "_id" , theid );
  157
+                }
  158
+                
  159
+                JSIdArray * properties = JS_Enumerate( _context , o );
  160
+                assert( properties );
  161
+                
  162
+                for ( jsint i=0; i<properties->length; i++ ){
  163
+                    jsid id = properties->vector[i];
  164
+                    jsval nameval;
  165
+                    assert( JS_IdToValue( _context ,id , &nameval ) );
  166
+                    string name = toString( nameval );
  167
+                    if ( name == "_id" )
  168
+                        continue;
  169
+                    
  170
+                    append( b , name , getProperty( o , name.c_str() ) , orig[name].type() );
  171
+                }
167 172
 
168  
-                append( b , name , getProperty( o , name.c_str() ) , orig[name].type() );
  173
+                JS_DestroyIdArray( _context , properties );
169 174
             }
170 175
 
171  
-            JS_DestroyIdArray( _context , properties );
172  
-
173 176
             return b.obj();
174 177
         }
175 178
 
12  scripting/sm_db.cpp
@@ -688,7 +688,7 @@ namespace mongo {
688 688
                              );
689 689
             return true;
690 690
         }
691  
-
  691
+        
692 692
 #if defined( SM16 ) || defined( MOZJS )
693 693
         {
694 694
             jsdouble d = js_DateGetMsecSinceEpoch( c->_context , o );
@@ -705,6 +705,14 @@ namespace mongo {
705 705
         }
706 706
 #endif
707 707
 
  708
+        
  709
+        if ( JS_InstanceOf( c->_context , o , &dbquery_class , 0 ) ||
  710
+             JS_InstanceOf( c->_context , o , &mongo_class , 0 ) || 
  711
+             JS_InstanceOf( c->_context , o , &db_collection_class , 0 ) ){
  712
+            b.append( name.c_str() , c->toString( OBJECT_TO_JSVAL(o) ) );
  713
+            return true;
  714
+        }
  715
+
708 716
 
709 717
         return false;
710 718
     }
@@ -716,5 +724,5 @@ namespace mongo {
716 724
         return JS_InstanceOf( cx , o, &js_DateClass, 0 );
717 725
 #endif
718 726
     }
719  
-
  727
+    
720 728
 }

0 notes on commit 294f9e4

Please sign in to comment.
Something went wrong with that request. Please try again.