diff --git a/services/native/src/shutdown/shutdown_dialog.cpp b/services/native/src/shutdown/shutdown_dialog.cpp index a748982ced57e82e6634096440db9ac634e141b2..9956675f11f472715c4c261fbec8a64373e3962e 100644 --- a/services/native/src/shutdown/shutdown_dialog.cpp +++ b/services/native/src/shutdown/shutdown_dialog.cpp @@ -194,6 +194,11 @@ void ShutdownDialog::LoadDialogConfig() return; } + if (root.isNull() || !root.isObject()) { + POWER_HILOGE(COMP_UTILS, "json root invalid[%{public}s]", contentStr.c_str()); + return; + } + if (!root["bundleName"].isString() || !root["abilityName"].isString() || !root["uiExtensionType"].isString()) { POWER_HILOGE(COMP_UTILS, "json varibale not support"); diff --git a/services/native/src/suspend/suspend_source_parser.cpp b/services/native/src/suspend/suspend_source_parser.cpp index d84084d82b9413695a6ae31bdf1df5b47984fec2..a0d8d05c603549352e780b2ad4719271ae7cce28 100644 --- a/services/native/src/suspend/suspend_source_parser.cpp +++ b/services/native/src/suspend/suspend_source_parser.cpp @@ -145,6 +145,11 @@ std::shared_ptr SuspendSourceParser::ParseSources(const std::str return parseSources; } + if (root.isNull() || !root.isObject()) { + POWER_HILOGE(FEATURE_SUSPEND, "json root invalid[%{public}s]", jsonStr.c_str()); + return parseSources; + } + Json::Value::Members members = root.getMemberNames(); for (auto iter = members.begin(); iter != members.end(); iter++) { std::string key = *iter; @@ -173,7 +178,7 @@ bool SuspendSourceParser::ParseSourcesProc( uint32_t action = 0; uint32_t delayMs = 0; - if (valueObj.isObject()) { + if (!valueObj.isNull() && valueObj.isObject()) { Json::Value actionValue = valueObj[SuspendSource::ACTION_KEY]; Json::Value delayValue = valueObj[SuspendSource::DELAY_KEY]; if (actionValue.isUInt() && delayValue.isUInt()) { diff --git a/services/native/src/wakeup/wakeup_source_parser.cpp b/services/native/src/wakeup/wakeup_source_parser.cpp index 6eb634cd080982dd2cd48ca1a6288ccb94c503a8..11287a1e225c528e226d74ca0ea889e1ed250cae 100644 --- a/services/native/src/wakeup/wakeup_source_parser.cpp +++ b/services/native/src/wakeup/wakeup_source_parser.cpp @@ -101,6 +101,11 @@ std::shared_ptr WakeupSourceParser::ParseSources(const std::strin return parseSources; } + if (root.isNull() || !root.isObject()) { + POWER_HILOGE(FEATURE_WAKEUP, "json root invalid[%{public}s]", jsonStr.c_str()); + return parseSources; + } + Json::Value::Members members = root.getMemberNames(); for (auto iter = members.begin(); iter != members.end(); iter++) { std::string key = *iter; @@ -122,7 +127,7 @@ bool WakeupSourceParser::ParseSourcesProc( bool enable = true; uint32_t click = DOUBLE_CLICK; WakeupDeviceType wakeupDeviceType = WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN; - if (valueObj.isObject()) { + if (!valueObj.isNull() && valueObj.isObject()) { Json::Value enableValue = valueObj[WakeupSource::ENABLE_KEY]; Json::Value clickValue = valueObj[WakeupSource::KEYS_KEY]; if (!clickValue.isNull() && clickValue.isUInt()) { diff --git a/services/native/src/wakeup_action/wakeup_action_source_parser.cpp b/services/native/src/wakeup_action/wakeup_action_source_parser.cpp index ab3c21cfb583a4d03449d40254f8dcb21fc0e946..9ea264050c9ac487b4908a579fb281395cc354b1 100644 --- a/services/native/src/wakeup_action/wakeup_action_source_parser.cpp +++ b/services/native/src/wakeup_action/wakeup_action_source_parser.cpp @@ -86,6 +86,11 @@ std::shared_ptr WakeupActionSourceParser::ParseSources(cons return parseSources; } + if (root.isNull() || !root.isObject()) { + POWER_HILOGE(FEATURE_WAKEUP_ACTION, "json root invalid[%{public}s]", jsonStr.c_str()); + return parseSources; + } + Json::Value::Members members = root.getMemberNames(); for (auto iter = members.begin(); iter != members.end(); iter++) { std::string key = *iter; @@ -105,7 +110,7 @@ bool WakeupActionSourceParser::ParseSourcesProc( { std::string scene{""}; uint32_t action = 0; - if (valueObj.isObject()) { + if (!valueObj.isNull() && valueObj.isObject()) { Json::Value sceneValue = valueObj[WakeupActionSource::SCENE_KEY]; Json::Value actionValue = valueObj[WakeupActionSource::ACTION_KEY]; if (sceneValue.isString()) {