diff --git a/extend/lbson/src/bson.h b/extend/lbson/src/bson.h index 4249159a..d55f9485 100644 --- a/extend/lbson/src/bson.h +++ b/extend/lbson/src/bson.h @@ -205,6 +205,10 @@ namespace lbson { if (!lua_isinteger(L, -2)) { return bson_type::BSON_DOCUMENT; } + size_t key = lua_tointeger(L, -2); + if (key <= 0 || key > raw_len) { + return bson_type::BSON_DOCUMENT; + } cur_len++; lua_pop(L, 1); } diff --git a/extend/lbson/src/lbson.cpp b/extend/lbson/src/lbson.cpp index a133cedc..8a1fcd6f 100644 --- a/extend/lbson/src/lbson.cpp +++ b/extend/lbson/src/lbson.cpp @@ -12,12 +12,6 @@ namespace lbson { static int decode(lua_State* L) { return thread_bson.decode(L); } - static slice* encode_slice(lua_State* L) { - return thread_bson.encode_slice(L); - } - static int decode_slice(lua_State* L, slice* slice) { - return thread_bson.decode_slice(L, slice); - } static bson_value* int32(int32_t value) { return new bson_value(bson_type::BSON_INT64, value); } @@ -50,8 +44,6 @@ namespace lbson { auto llbson = kit_state.new_table(); llbson.set_function("encode", encode); llbson.set_function("decode", decode); - llbson.set_function("encode_slice", encode_slice); - llbson.set_function("decode_slice", decode_slice); llbson.set_function("mongocodec", mongo_codec); llbson.set_function("timestamp", timestamp); llbson.set_function("int32", int32); diff --git a/extend/lcodec/src/websocket.h b/extend/lcodec/src/websocket.h index cbec2ab7..19770981 100644 --- a/extend/lcodec/src/websocket.h +++ b/extend/lcodec/src/websocket.h @@ -16,7 +16,8 @@ namespace lcodec { uint8_t masklen = (((*payload) & 0x80) == 0x80) ? 4 : 0; uint8_t payloadlen = (*payload) & 0x7f; if (payloadlen < 0x7e) { - return masklen + payloadlen + sizeof(uint16_t); + m_packet_len = masklen + payloadlen + sizeof(uint16_t); + return m_packet_len; } size_t* length = (size_t*)m_slice->peek((payloadlen == 0x7f) ? 8 : 2, sizeof(uint16_t)); if (!length) return 0; diff --git a/extend/ljson/src/ljson.h b/extend/ljson/src/ljson.h index 4ad41863..771b4f57 100644 --- a/extend/ljson/src/ljson.h +++ b/extend/ljson/src/ljson.h @@ -62,6 +62,10 @@ namespace ljson { if (!lua_isinteger(L, -2)) { return false; } + size_t key = lua_tointeger(L, -2); + if (key <= 0 || key > raw_len) { + return false; + } lua_pop(L, 1); cur_len++; } diff --git a/extend/luakit/include/lua_codec.h b/extend/luakit/include/lua_codec.h index 78017b8f..39723e0e 100644 --- a/extend/luakit/include/lua_codec.h +++ b/extend/luakit/include/lua_codec.h @@ -56,6 +56,10 @@ namespace luakit { if (!lua_isinteger(L, -2)) { return false; } + size_t key = lua_tointeger(L, -2); + if (key <= 0 || key > raw_len) { + return false; + } cur_len++; lua_pop(L, 1); } diff --git a/script/driver/websocket.lua b/script/driver/websocket.lua index 3ff76917..436cea43 100644 --- a/script/driver/websocket.lua +++ b/script/driver/websocket.lua @@ -12,6 +12,7 @@ local qxpcall = quanta.xpcall local proto_text = luabus.eproto_type.text +local event_mgr = quanta.get("event_mgr") local socket_mgr = quanta.get("socket_mgr") local thread_mgr = quanta.get("thread_mgr") @@ -152,7 +153,9 @@ function WebSocket:on_handshake(session, token, url, params, headers, body) self.session = session self:send_data(101, cbheaders, "") self.host:on_socket_accept(self, token) - session.set_codec(self.wcodec) + event_mgr:fire_frame(function() + session.set_codec(self.wcodec) + end) return true end diff --git a/server/robot/accord_mgr.lua b/server/robot/accord_mgr.lua index 86baebc0..76f7786c 100644 --- a/server/robot/accord_mgr.lua +++ b/server/robot/accord_mgr.lua @@ -2,9 +2,7 @@ local log_warn = logger.warn local log_debug = logger.debug local jdecode = json.decode -local jencode = json.encode local json_pretty = json.pretty -local tinsert = table.insert local HttpServer = import("network/http_server.lua") @@ -202,9 +200,9 @@ function AccordMgr:on_case_group_del(url, body) if not group then return { code = 0 } end - for id,accord in pairs(self.accord_list) do + for aid, accord in pairs(self.accord_list) do if group.name == accord.casegroup then - accord_dao:delete("accord_conf", id) + accord_dao:delete("accord_conf", aid) end end self.case_group[id] = nil diff --git a/server/robot/dao/accord_dao.lua b/server/robot/dao/accord_dao.lua index e7b68c3d..7344c0fa 100644 --- a/server/robot/dao/accord_dao.lua +++ b/server/robot/dao/accord_dao.lua @@ -22,7 +22,7 @@ end -- 插入数据 function AccordDao:insert(document, data) - local code, res = mongo_mgr:insert(1, mrandom(), document, data) + local code = mongo_mgr:insert(1, mrandom(), document, data) if code ~= SUCCESS then log_debug("[AccordDao][insert] document:{} code:{}", document, code) return false @@ -33,7 +33,7 @@ end -- 更新数据 function AccordDao:update(document, data) local udata = { ["$set"] = data } - local code, res = mongo_mgr:update(1, mrandom(), document, udata, { id = data.id }) + local code = mongo_mgr:update(1, mrandom(), document, udata, { id = data.id }) if code ~= SUCCESS then log_debug("[AccordDao][update] document:{} code:{}", document, code) return false @@ -43,7 +43,7 @@ end -- 删除数据 function AccordDao:delete(document, id) - local code, res = mongo_mgr:delete(1, mrandom(), document, {id=id}) + local code = mongo_mgr:delete(1, mrandom(), document, {id=id}) if code ~= SUCCESS then log_debug("[AccordDao][delete] document:{} code:{}", document, code) return false diff --git a/server/robot/msg_mgr.lua b/server/robot/msg_mgr.lua index 81c60618..e0977785 100644 --- a/server/robot/msg_mgr.lua +++ b/server/robot/msg_mgr.lua @@ -1,7 +1,5 @@ -- robot_mgr.lua -local log_err = logger.err -local log_debug = logger.debug local pb_enum_id = protobuf.enum local supper = string.upper local tunpack = table.unpack