!34 json反序列化增加校验

Merge pull request !34 from 李天刚/master
This commit is contained in:
openharmony_ci
2023-06-25 06:35:15 +00:00
committed by Gitee
4 changed files with 25 additions and 1 deletions
@@ -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()) {
@@ -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()) {
@@ -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) {
+1 -1
View File
@@ -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) {