From 6026ace2cea26133dad0bd9dd43ccc5259852c0b Mon Sep 17 00:00:00 2001 From: litiangang4 Date: Tue, 20 Jun 2023 11:35:07 +0800 Subject: [PATCH] =?UTF-8?q?json=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: litiangang4 --- .../transport/src/distributed_input_sink_transport.cpp | 8 ++++++++ .../transport/src/distributed_input_source_transport.cpp | 8 ++++++++ .../src/distributed_input_transport_base.cpp | 8 ++++++++ utils/src/dinput_utils_tool.cpp | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index bbe6ffb..abf5118 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -463,6 +463,14 @@ void DistributedInputSinkTransport::HandleData(int32_t sessionId, const std::str } nlohmann::json recMsg = nlohmann::json::parse(message, nullptr, false); + if (recMsg.is_discarded()) { + DHLOGE("recMsg parse failed!"); + return; + } + if (!IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_CMD_TYPE)) { + DHLOGE("softbus cmd key is invalid"); + return; + } uint32_t cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE]; auto iter = memberFuncMap_.find(cmdType); if (iter == memberFuncMap_.end()) { diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 841b8cb..e8676da 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -1470,6 +1470,14 @@ void DistributedInputSourceTransport::HandleData(int32_t sessionId, const std::s } nlohmann::json recMsg = nlohmann::json::parse(message, nullptr, false); + if (recMsg.is_discarded()) { + DHLOGE("recMsg parse failed!"); + return; + } + if (!IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_CMD_TYPE)) { + DHLOGE("softbus cmd key is invalid"); + return; + } uint32_t cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE]; auto iter = memberFuncMap_.find(cmdType); if (iter == memberFuncMap_.end()) { diff --git a/services/transportbase/src/distributed_input_transport_base.cpp b/services/transportbase/src/distributed_input_transport_base.cpp index f667a55..fb058e1 100644 --- a/services/transportbase/src/distributed_input_transport_base.cpp +++ b/services/transportbase/src/distributed_input_transport_base.cpp @@ -412,6 +412,14 @@ void DistributedInputTransportBase::HandleSession(int32_t sessionId, const std:: return; } nlohmann::json recMsg = nlohmann::json::parse(message, nullptr, false); + if (recMsg.is_discarded()) { + DHLOGE("recMsg parse failed!"); + return; + } + if (!IsUInt32(recMsg, DINPUT_SOFTBUS_KEY_CMD_TYPE)) { + DHLOGE("softbus cmd key is invalid"); + return; + } uint32_t cmdType = recMsg[DINPUT_SOFTBUS_KEY_CMD_TYPE]; DHLOGI("HandleSession cmdType %u.", cmdType); if (cmdType < TRANS_MSG_SRC_SINK_SPLIT) { diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 48fc186..0cda783 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -45,6 +45,7 @@ namespace { constexpr int32_t WIDTH = 4; constexpr unsigned char MASK = 0x0F; constexpr int32_t DOUBLE_TIMES = 2; + constexpr int32_t INT32_STRING_LENGTH = 40; } DevInfo GetLocalDeviceInfo() { @@ -248,7 +249,6 @@ std::string GetAnonyString(const std::string &value) std::string GetAnonyInt32(const int32_t value) { - constexpr int32_t INT32_STRING_LENGTH = 40; char tempBuffer[INT32_STRING_LENGTH] = ""; int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); if (secRet <= 0) { -- Gitee