mirror of https://github.com/redis/redis.git
				
				
				
			Security: more cmsgpack fixes by @soloestoy.
@soloestoy sent me this additional fixes, after searching for similar problems to the one reported in mp_pack(). I'm committing the changes because it was not possible during to make a public PR to protect Redis users and give Redis providers some time to patch their systems.
This commit is contained in:
		
							parent
							
								
									1eb08bcd46
								
							
						
					
					
						commit
						5ccb6f7a79
					
				|  | @ -385,6 +385,7 @@ void mp_encode_lua_table_as_array(lua_State *L, mp_buf *buf, int level) { | |||
| #endif | ||||
| 
 | ||||
|     mp_encode_array(L,buf,len); | ||||
|     luaL_checkstack(L, 1, "in function mp_encode_lua_table_as_array"); | ||||
|     for (j = 1; j <= len; j++) { | ||||
|         lua_pushnumber(L,j); | ||||
|         lua_gettable(L,-2); | ||||
|  | @ -400,6 +401,7 @@ void mp_encode_lua_table_as_map(lua_State *L, mp_buf *buf, int level) { | |||
|      * Lua API, we need to iterate a first time. Note that an alternative | ||||
|      * would be to do a single run, and then hack the buffer to insert the | ||||
|      * map opcodes for message pack. Too hackish for this lib. */ | ||||
|     luaL_checkstack(L, 3, "in function mp_encode_lua_table_as_map"); | ||||
|     lua_pushnil(L); | ||||
|     while(lua_next(L,-2)) { | ||||
|         lua_pop(L,1); /* remove value, keep key for next iteration. */ | ||||
|  | @ -522,6 +524,7 @@ int mp_pack(lua_State *L) { | |||
|     for(i = 1; i <= nargs; i++) { | ||||
|         /* Copy argument i to top of stack for _encode processing;
 | ||||
|          * the encode function pops it from the stack when complete. */ | ||||
|         luaL_checkstack(L, 1, "in function mp_check"); | ||||
|         lua_pushvalue(L, i); | ||||
| 
 | ||||
|         mp_encode_lua_type(L,buf,0); | ||||
|  | @ -550,6 +553,7 @@ void mp_decode_to_lua_array(lua_State *L, mp_cur *c, size_t len) { | |||
|     int index = 1; | ||||
| 
 | ||||
|     lua_newtable(L); | ||||
|     luaL_checkstack(L, 1, "in function mp_decode_to_lua_array"); | ||||
|     while(len--) { | ||||
|         lua_pushnumber(L,index++); | ||||
|         mp_decode_to_lua_type(L,c); | ||||
|  | @ -824,6 +828,9 @@ int mp_unpack_full(lua_State *L, int limit, int offset) { | |||
|          * subtract the entire buffer size from the unprocessed size | ||||
|          * to get our next start offset */ | ||||
|         int offset = len - c.left; | ||||
| 
 | ||||
|         luaL_checkstack(L, 1, "in function mp_unpack_full"); | ||||
| 
 | ||||
|         /* Return offset -1 when we have have processed the entire buffer. */ | ||||
|         lua_pushinteger(L, c.left == 0 ? -1 : offset); | ||||
|         /* Results are returned with the arg elements still
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue