File tree 3 files changed +19
-3
lines changed
3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,13 @@ struct bson_reader {
68
68
int size ;
69
69
};
70
70
71
+ static inline int32_t
72
+ get_length (const uint8_t * data ) {
73
+ const uint8_t * b = (const uint8_t * )data ;
74
+ int32_t len = b [0 ] | b [1 ]<<8 | b [2 ]<<16 | b [3 ]<<24 ;
75
+ return len ;
76
+ }
77
+
71
78
static inline void
72
79
bson_destroy (struct bson * b ) {
73
80
if (b -> ptr != b -> buffer ) {
@@ -644,7 +651,7 @@ static int
644
651
lmakeindex (lua_State * L ) {
645
652
int32_t * bson = luaL_checkudata (L ,1 ,"bson" );
646
653
const uint8_t * start = (const uint8_t * )bson ;
647
- struct bson_reader br = { start + 4 , * bson - 5 };
654
+ struct bson_reader br = { start + 4 , get_length ( start ) - 5 };
648
655
lua_newtable (L );
649
656
650
657
for (;;) {
@@ -820,7 +827,9 @@ ldecode(lua_State *L) {
820
827
if (data == NULL ) {
821
828
return 0 ;
822
829
}
823
- struct bson_reader br = { (const uint8_t * )data , * data };
830
+ const uint8_t * b = (const uint8_t * )data ;
831
+ int32_t len = get_length (b );
832
+ struct bson_reader br = { b , len };
824
833
825
834
unpack_dict (L , & br , false);
826
835
Original file line number Diff line number Diff line change @@ -260,6 +260,13 @@ op_reply(lua_State *L) {
260
260
lua_pushnil (L );
261
261
lua_rawseti (L , 2 , i );
262
262
}
263
+ } else {
264
+ if (sz >= 4 ) {
265
+ sz -= get_length ((document )doc );
266
+ }
267
+ }
268
+ if (sz != 0 ) {
269
+ return luaL_error (L , "Invalid result bson document" );
263
270
}
264
271
lua_pushboolean (L ,1 );
265
272
lua_pushinteger (L , id );
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ function mongo.client( conf )
98
98
host = obj .host ,
99
99
port = obj .port ,
100
100
response = dispatch_reply ,
101
- auth = mongo_auth (conf ),
101
+ auth = mongo_auth (obj ),
102
102
}
103
103
setmetatable (obj , client_meta )
104
104
obj .__sock :connect (true ) -- try connect only once
You can’t perform that action at this time.
0 commit comments