From 494097fad21b02edee9d9a61ad9378ea437f3768 Mon Sep 17 00:00:00 2001 From: vv Date: Tue, 9 Jul 2024 11:47:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=89=E5=85=A8=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/data_buffer_test.cpp | 12 +++++++++++ .../src/callback/dcamera_sink_callback.cpp | 4 ++++ .../src/dcamera_sink_handler_ipc.cpp | 4 ++-- .../src/distributed_camera_sink_proxy.cpp | 2 +- .../src/dcamera_source_handler_ipc.cpp | 4 ++-- .../callbackonnotifyresourceinfo_fuzzer.cpp | 3 +++ .../callbacksinkonremoterequest_fuzzer.cpp | 6 ++++++ .../callbackonnotifyregresult_fuzzer.cpp | 3 +++ .../callbackonnotifyunregresult_fuzzer.cpp | 3 +++ .../callbackonremoterequest_fuzzer.cpp | 3 +++ .../camera_sink/dcamera_sink_handler_test.cpp | 9 ++++++++ .../callback/dcamera_source_callback_test.cpp | 21 +++++++++++++++++++ .../dcamera_source_handler_test.cpp | 6 ++++++ .../base/src/dcamera_capture_info_cmd.cpp | 7 +++++++ .../base/src/dcamera_channel_info_cmd.cpp | 8 +++++++ .../base/src/dcamera_event_cmd.cpp | 2 +- .../base/src/dcamera_info_cmd.cpp | 2 +- .../base/src/dcamera_metadata_setting_cmd.cpp | 2 +- .../base/src/dcamera_open_info_cmd.cpp | 2 +- 19 files changed, 94 insertions(+), 9 deletions(-) diff --git a/common/test/unittest/common/utils/data_buffer_test.cpp b/common/test/unittest/common/utils/data_buffer_test.cpp index b973c6c5..8730d1ac 100644 --- a/common/test/unittest/common/utils/data_buffer_test.cpp +++ b/common/test/unittest/common/utils/data_buffer_test.cpp @@ -67,6 +67,9 @@ HWTEST_F(DataBufferTest, SetRange_001, TestSize.Level1) { size_t offset = 0; size_t size = 0; + if(dataBuffer_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = dataBuffer_->SetRange(offset, size); EXPECT_EQ(DCAMERA_OK, ret); offset = dataBuffer_->Offset() + 2; @@ -85,6 +88,9 @@ HWTEST_F(DataBufferTest, FindInt32_001, TestSize.Level1) { string name = "test"; int32_t value = 1; + if(dataBuffer_ == nullptr) { + return DCAMERA_BAD_VALUE; + } dataBuffer_->SetInt32(name, value); bool ret = dataBuffer_->FindInt32(name, value); EXPECT_EQ(true, ret); @@ -103,6 +109,9 @@ HWTEST_F(DataBufferTest, FindInt62_001, TestSize.Level1) { string name = "test"; int64_t value = 1; + if(dataBuffer_ == nullptr) { + return DCAMERA_BAD_VALUE; + } dataBuffer_->SetInt64(name, value); bool ret = dataBuffer_->FindInt64(name, value); EXPECT_EQ(true, ret); @@ -121,6 +130,9 @@ HWTEST_F(DataBufferTest, FindString_001, TestSize.Level1) { string name = "test"; string value = "test"; + if(dataBuffer_ == nullptr) { + return DCAMERA_BAD_VALUE; + } dataBuffer_->SetString(name, value); bool ret = dataBuffer_->FindString(name, value); EXPECT_EQ(true, ret); diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp index 4cac74bf..9db30fb4 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp @@ -36,6 +36,10 @@ int32_t DCameraSinkCallback::OnNotifyResourceInfo(const ResourceEventType &type, std::lock_guard lock(privacyResMutex_); auto iter = privacyResCallback_.begin(); if (iter != privacyResCallback_.end()) { + if (*iter == nullptr){ + DHLOGE("GetSystemAbility failed"); + return DCAMERA_BAD_VALUE; + } ret = (*iter)->OnPrivaceResourceMessage(type, subtype, networkId, isSensitive, isSameAccout); } return ret; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler_ipc.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler_ipc.cpp index f18e120c..9a90becc 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler_ipc.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler_ipc.cpp @@ -97,7 +97,7 @@ sptr DCameraSinkHandlerIpc::GetSinkLocalCamSrv() } { std::lock_guard autoLock(sinkLocalCamSrvLock_); - if (localSink_ != nullptr) { + if (localSink_ != nullptr && localSink_->AsObject() != nullptr) { localSink_->AsObject()->RemoveDeathRecipient(sinkLocalRecipient_); } localSink_ = localSink; @@ -110,7 +110,7 @@ void DCameraSinkHandlerIpc::DeleteSinkLocalCamSrv() { DHLOGI("start"); std::lock_guard autoLock(sinkLocalCamSrvLock_); - if (localSink_ != nullptr) { + if (localSink_ != nullptr && localSink_->AsObject()) { localSink_->AsObject()->RemoveDeathRecipient(sinkLocalRecipient_); } localSink_ = nullptr; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp index cb4a5985..31214a89 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp @@ -48,7 +48,7 @@ int32_t DistributedCameraSinkProxy::InitSink(const std::string& params, const sp DHLOGE("write params failed"); return DCAMERA_BAD_VALUE; } - if (!data.WriteRemoteObject(sinkCallback->AsObject())) { + if (sinkCallback->AsObject() != nullptr && !data.WriteRemoteObject(sinkCallback->AsObject())) { DHLOGE("write sinkCallback failed"); return DCAMERA_BAD_VALUE; } diff --git a/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp b/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp index 36317d84..64baee13 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp +++ b/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp @@ -97,7 +97,7 @@ sptr DCameraSourceHandlerIpc::GetSourceLocalCamSrv() } { std::lock_guard autoLock(sourceLocalCamSrvLock_); - if (localSource_ != nullptr) { + if (localSource_ != nullptr && localSource_->AsObject() != nullptr) { localSource_->AsObject()->RemoveDeathRecipient(sourceLocalRecipient_); } localSource_ = localSource; @@ -110,7 +110,7 @@ void DCameraSourceHandlerIpc::DeleteSourceLocalCamSrv() { DHLOGI("start"); std::lock_guard autoLock(sourceLocalCamSrvLock_); - if (localSource_ != nullptr) { + if (localSource_ != nullptr && localSource_->AsObject() != nullptr) { localSource_->AsObject()->RemoveDeathRecipient(sourceLocalRecipient_); } localSource_ = nullptr; diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp index f803426b..cad43507 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbackonnotifyresourceinfo_fuzzer/callbackonnotifyresourceinfo_fuzzer.cpp @@ -42,6 +42,9 @@ void CallbackOnNotifyResourceInfoFuzzTest(const uint8_t* data, size_t size) std::shared_ptr callback = std::make_shared(); sptr dcameraSinkCallback(new (std::nothrow) DCameraSinkCallback()); + if (dcameraSinkCallback == nullptr) { + return; + } dcameraSinkCallback->PushPrivacyResCallback(callback); dcameraSinkCallback->OnNotifyResourceInfo(type, subtype, networkId, isSensitive, isSameAccout); } diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbacksinkonremoterequest_fuzzer/callbacksinkonremoterequest_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbacksinkonremoterequest_fuzzer/callbacksinkonremoterequest_fuzzer.cpp index 8b4f0bf2..bcc66df0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbacksinkonremoterequest_fuzzer/callbacksinkonremoterequest_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/callbacksinkonremoterequest_fuzzer/callbacksinkonremoterequest_fuzzer.cpp @@ -53,6 +53,9 @@ void CallbackSinkOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) pdata.ReadBool(isSameAccout); sptr dcameraSinkCallback(new (std::nothrow) DCameraSinkCallback()); + if (dcameraSinkCallback == nullptr) { + return; + } dcameraSinkCallback->memberFuncMap_[code] = &DCameraSinkCallbackStub::OnNotifyResourceInfoInner; dcameraSinkCallback->OnRemoteRequest(code, pdata, reply, option); } @@ -76,6 +79,9 @@ void CallbackSinkOnNotifyResourceInfoInnerFuzzTest(const uint8_t* data, size_t s pdata.ReadBool(isSameAccout); sptr dcameraSinkCallback(new (std::nothrow) DCameraSinkCallback()); + if (dcameraSinkCallback == nullptr) { + return; + } dcameraSinkCallback->OnNotifyResourceInfoInner(pdata, reply); } } diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp index 77072bfa..86582342 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp @@ -34,6 +34,9 @@ void CallbackOnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) std::shared_ptr callback = std::make_shared(); sptr dcameraSourceCallback(new (std::nothrow) DCameraSourceCallback()); + if (dcameraSourceCallback == nullptr) { + return; + } dcameraSourceCallback->PushRegCallback(reqId, callback); dcameraSourceCallback->OnNotifyRegResult(devId, dhId, reqId, status, dataStr); } diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp index babcb071..518e8a64 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp @@ -34,6 +34,9 @@ void CallbackOnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) std::shared_ptr uncallback = std::make_shared(); sptr dcameraSourceCallback(new (std::nothrow) DCameraSourceCallback()); + if (dcameraSourceCallback == nullptr){ + return; + } dcameraSourceCallback->PushUnregCallback(reqId, uncallback); dcameraSourceCallback->OnNotifyRegResult(devId, dhId, reqId, status, dataStr); } diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp index fc9ed0ad..20d2ce26 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp @@ -46,6 +46,9 @@ void CallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) pdata.WriteString(dataStr); sptr dcameraSourceCallback(new (std::nothrow) DCameraSourceCallback()); + if (dcameraSourceCallback == nullptr) { + return; + } dcameraSourceCallback->OnRemoteRequest(code, pdata, reply, option); } } diff --git a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/dcamera_sink_handler_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/dcamera_sink_handler_test.cpp index cdec2924..3958724b 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/dcamera_sink_handler_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_sink/dcamera_sink_handler_test.cpp @@ -170,6 +170,9 @@ HWTEST_F(DCameraSinkHandlerTest, dcamera_sink_handler_test_005, TestSize.Level1) SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sptr remoteObject = samgr->GetSystemAbility(systemAbilityId); sptr loadCallback(new DCameraSinkLoadCallback(params)); + if(loadCallback == nullptr) { + return DCAMERA_BAD_VALUE; + } loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); remoteObject = nullptr; @@ -191,6 +194,9 @@ HWTEST_F(DCameraSinkHandlerTest, dcamera_sink_handler_test_006, TestSize.Level1) std::string params = "test006"; int32_t systemAbilityId = 4804; sptr loadCallback(new DCameraSinkLoadCallback(params)); + if(loadCallback == nullptr) { + return DCAMERA_BAD_VALUE; + } loadCallback->OnLoadSystemAbilityFail(systemAbilityId); systemAbilityId = 1; @@ -257,6 +263,9 @@ HWTEST_F(DCameraSinkHandlerTest, dcamera_sink_handler_test_010, TestSize.Level1) SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sptr remoteObject = samgr->GetSystemAbility(systemAbilityId); sptr loadCallback(new DCameraSinkLoadCallback(params)); + if(loadCallback == nullptr) { + return DCAMERA_BAD_VALUE; + } loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); remoteObject = nullptr; diff --git a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/callback/dcamera_source_callback_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/callback/dcamera_source_callback_test.cpp index e0508530..ea74f770 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/callback/dcamera_source_callback_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/callback/dcamera_source_callback_test.cpp @@ -143,6 +143,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_002, TestSize.L std::string reqId = "reqId"; int32_t status = 0; std::string data = "data"; + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->OnNotifyRegResult(devId, dhId, reqId, status, data); EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } @@ -180,6 +183,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_004, TestSize.L std::string reqId = "reqId"; int32_t status = 0; std::string data = "data"; + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->OnNotifyUnregResult(devId, dhId, reqId, status, data); EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } @@ -196,6 +202,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_005, TestSize.L std::string dhId = "dhId"; std::string reqId = "reqId"; std::string result = "result"; + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->CheckParams(devId, dhId, reqId, result); EXPECT_EQ(false, ret); devId += std::string(DID_MAX_SIZE + 1, 'a'); @@ -243,6 +252,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_006, TestSize.L data.WriteString(devId); data.WriteString(dhId); data.WriteString(reqId); + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->OnRemoteRequest(code, data, reply, option); EXPECT_NE(DCAMERA_OK, ret); code = DCameraSourceCallback::NOTIFY_REG_RESULT; @@ -298,6 +310,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_008, TestSize.L data.WriteString(reqId); data.WriteInt32(status); data.WriteString(result); + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->NotifyUnregResultInner(data, reply); sourceCallback_->RegisterStateListener(nullptr); sourceCallback_->UnRegisterStateListener(); @@ -317,6 +332,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_009, TestSize.L std::string devId = "devId"; std::string dhId = "dhId"; int32_t status = 1; + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->OnHardwareStateChanged(devId, dhId, status); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); std::shared_ptr listener = @@ -354,6 +372,9 @@ HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_009, TestSize.L HWTEST_F(DCameraSourceCallbackTest, dcamera_source_callback_test_010, TestSize.Level1) { std::string devId = ""; + if(sourceCallback_ == nullptr) { + return DCAMERA_BAD_VALUE; + } int32_t ret = sourceCallback_->OnDataSyncTrigger(devId); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); devId += std::string(DID_MAX_SIZE + 1, 'a'); diff --git a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/dcamera_source_handler_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/dcamera_source_handler_test.cpp index 1908a0ee..c728cc7d 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/dcamera_source_handler_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/common/camera_source/dcamera_source_handler_test.cpp @@ -156,6 +156,9 @@ HWTEST_F(DCameraSourceHandlerTest, dcamera_source_handler_test_005, TestSize.Lev SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sptr remoteObject = samgr->GetSystemAbility(systemAbilityId); sptr loadCallback(new DCameraSourceLoadCallback(params)); + if(loadCallback == nullptr) { + return DCAMERA_BAD_VALUE; + } loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); remoteObject = nullptr; @@ -177,6 +180,9 @@ HWTEST_F(DCameraSourceHandlerTest, dcamera_source_handler_test_006, TestSize.Lev std::string params = "test006"; int32_t systemAbilityId = 4803; sptr loadCallback(new DCameraSourceLoadCallback(params)); + if(loadCallback == nullptr) { + return DCAMERA_BAD_VALUE; + } loadCallback->OnLoadSystemAbilityFail(systemAbilityId); systemAbilityId = 1; diff --git a/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp b/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp index 1a008f31..b7c83431 100644 --- a/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_capture_info_cmd.cpp @@ -42,6 +42,10 @@ int32_t DCameraCaptureInfoCmd::Marshal(std::string& jsonStr) } cJSON_AddItemToArray(captureInfos, captureInfo); std::shared_ptr capture = *iter; + if (capture == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } cJSON_AddNumberToObject(captureInfo, "Width", capture->width_); cJSON_AddNumberToObject(captureInfo, "Height", capture->height_); cJSON_AddNumberToObject(captureInfo, "Format", capture->format_); @@ -156,6 +160,9 @@ int32_t DCameraCaptureInfoCmd::UmarshalValue(cJSON *rootValue) int32_t DCameraCaptureInfoCmd::UmarshalSettings(cJSON *valueJson, std::shared_ptr& captureInfo) { + if (captureInfo == nullptr) { + return DCAMERA_BAD_VALUE; + } cJSON *captureSetting = nullptr; cJSON_ArrayForEach(captureSetting, valueJson) { cJSON *settingType = cJSON_GetObjectItemCaseSensitive(captureSetting, "SettingType"); diff --git a/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp b/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp index 20846903..6d65e598 100644 --- a/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp @@ -27,6 +27,10 @@ int32_t DCameraChannelInfoCmd::Marshal(std::string& jsonStr) if (rootValue == nullptr) { return DCAMERA_BAD_VALUE; } + if (value_ == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); @@ -119,6 +123,10 @@ int32_t DCameraChannelInfoCmd::Unmarshal(const std::string& jsonStr) int32_t DCameraChannelInfoCmd::UnmarshalDetails(cJSON *details, std::shared_ptr channelInfo) { + if (channelInfo == nullptr ) { + return DCAMERA_BAD_VALUE; + } + DC cJSON *detail = nullptr; cJSON_ArrayForEach(detail, details) { cJSON *dataSessionFlag = cJSON_GetObjectItemCaseSensitive(detail, "DataSessionFlag"); diff --git a/services/cameraservice/base/src/dcamera_event_cmd.cpp b/services/cameraservice/base/src/dcamera_event_cmd.cpp index 2c4c8873..3a6805b0 100644 --- a/services/cameraservice/base/src/dcamera_event_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_event_cmd.cpp @@ -32,7 +32,7 @@ int32_t DCameraEventCmd::Marshal(std::string& jsonStr) cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); cJSON *event = cJSON_CreateObject(); - if (event == nullptr) { + if (event == nullptr || value_ == nullptr) { cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } diff --git a/services/cameraservice/base/src/dcamera_info_cmd.cpp b/services/cameraservice/base/src/dcamera_info_cmd.cpp index 0f950f7f..ef3408c6 100644 --- a/services/cameraservice/base/src/dcamera_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_info_cmd.cpp @@ -33,7 +33,7 @@ int32_t DCameraInfoCmd::Marshal(std::string& jsonStr) cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); cJSON *info = cJSON_CreateObject(); - if (info == nullptr) { + if (info == nullptr || value_ == nullptr) { cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } diff --git a/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp b/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp index 8688b0bc..549e9a15 100644 --- a/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp @@ -40,7 +40,7 @@ int32_t DCameraMetadataSettingCmd::Marshal(std::string& jsonStr) cJSON_AddItemToObject(rootValue, "Value", settings); for (auto iter = value_.begin(); iter != value_.end(); iter++) { cJSON *setting = cJSON_CreateObject(); - if (setting == nullptr) { + if (setting == nullptr || (*iter) == nullptr) { cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } diff --git a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp index 3b926476..a2da7014 100644 --- a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp @@ -33,7 +33,7 @@ int32_t DCameraOpenInfoCmd::Marshal(std::string& jsonStr) cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); cJSON *openInfo = cJSON_CreateObject(); - if (openInfo == nullptr) { + if (openInfo == nullptr == value_ == nullptr) { cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } -- Gitee From 41e6877f5013ac3803a8561de26a6e313d3ceb81 Mon Sep 17 00:00:00 2001 From: vv Date: Tue, 9 Jul 2024 15:53:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=89=E5=85=A8=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cameraservice/base/src/dcamera_channel_info_cmd.cpp | 8 -------- services/cameraservice/base/src/dcamera_open_info_cmd.cpp | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp b/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp index 6d65e598..20846903 100644 --- a/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_channel_info_cmd.cpp @@ -27,10 +27,6 @@ int32_t DCameraChannelInfoCmd::Marshal(std::string& jsonStr) if (rootValue == nullptr) { return DCAMERA_BAD_VALUE; } - if (value_ == nullptr) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); @@ -123,10 +119,6 @@ int32_t DCameraChannelInfoCmd::Unmarshal(const std::string& jsonStr) int32_t DCameraChannelInfoCmd::UnmarshalDetails(cJSON *details, std::shared_ptr channelInfo) { - if (channelInfo == nullptr ) { - return DCAMERA_BAD_VALUE; - } - DC cJSON *detail = nullptr; cJSON_ArrayForEach(detail, details) { cJSON *dataSessionFlag = cJSON_GetObjectItemCaseSensitive(detail, "DataSessionFlag"); diff --git a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp index a2da7014..edd6629b 100644 --- a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp +++ b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp @@ -33,7 +33,7 @@ int32_t DCameraOpenInfoCmd::Marshal(std::string& jsonStr) cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); cJSON *openInfo = cJSON_CreateObject(); - if (openInfo == nullptr == value_ == nullptr) { + if (openInfo == nullptr || value_ == nullptr) { cJSON_Delete(rootValue); return DCAMERA_BAD_VALUE; } -- Gitee