diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 11563ec6ad5c252bd5d650ff9316217971c73840..92524efdd91bf18d073632e82d23ec4e3ff55ade 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -34,6 +34,16 @@ config("ans_innerkits_public_config") { } ohos_shared_library("ans_innerkits") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + include_dirs = [ "${inner_api_path}" ] sources = [ diff --git a/frameworks/ans/src/notification_multiline_content.cpp b/frameworks/ans/src/notification_multiline_content.cpp index f25b9841a55e240d75fec491f5a16d3c751162e6..8fdb23049a890c98778ed0b2576ebfe9a6d757d4 100644 --- a/frameworks/ans/src/notification_multiline_content.cpp +++ b/frameworks/ans/src/notification_multiline_content.cpp @@ -63,7 +63,9 @@ std::string NotificationMultiLineContent::Dump() std::string lines {}; std::for_each( allLines_.begin(), allLines_.end(), [&lines](const std::string &line) { lines += " " + line + ","; }); - lines.pop_back(); + if (!lines.empty()) { + lines.pop_back(); + } return "NotificationMultiLineContent{ " + NotificationBasicContent::Dump() + ", briefText = " + briefText_ + diff --git a/frameworks/ans/src/notification_user_input.cpp b/frameworks/ans/src/notification_user_input.cpp index baab204a5212866ea08e1554fc1b02ee7b7cecb0..53f928e0569a95f2a9310417ec9d45035c8f1041 100644 --- a/frameworks/ans/src/notification_user_input.cpp +++ b/frameworks/ans/src/notification_user_input.cpp @@ -209,15 +209,23 @@ std::string NotificationUserInput::Dump() for (std::string option : options_) { options += option + ", "; } - options.pop_back(); - options.pop_back(); + if (!options.empty()) { + options.pop_back(); + } + if (!options.empty()) { + options.pop_back(); + } std::string permitMimeTypes; for (auto permitMimeType : permitMimeTypes_) { permitMimeTypes += permitMimeType + ", "; } - permitMimeTypes.pop_back(); - permitMimeTypes.pop_back(); + if (!permitMimeTypes.empty()) { + permitMimeTypes.pop_back(); + } + if (!permitMimeTypes.empty()) { + permitMimeTypes.pop_back(); + } return "NotificationUserInput{ " "inputKey = " + inputKey_ + @@ -408,4 +416,4 @@ bool NotificationUserInput::ReadFromParcel(Parcel &parcel) return true; } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp index 3d0e8cc13233f843a64458f925cfbbdde3d85fab..2bec0a079ac49d785f963407435d48fcbab9ea73 100644 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ b/frameworks/ans/src/reminder_request_calendar.cpp @@ -266,11 +266,17 @@ bool ReminderRequestCalendar::IsRepeatReminder() const bool ReminderRequestCalendar::IsRepeatMonth(uint8_t month) const { + if (month > MAX_MONTHS_OF_YEAR) { + return false; + } return (repeatMonth_ & (1 << (month - 1))) > 0; } bool ReminderRequestCalendar::IsRepeatDay(uint8_t day) const { + if (day > MAX_DAYS_OF_MONTH) { + return false; + } return (repeatDay_ & (1 << (day - 1))) > 0; } @@ -611,4 +617,4 @@ void ReminderRequestCalendar::InitDbColumns() ReminderRequest::AddColumn(CALENDAR_MINUTE, "INT", false); } } -} \ No newline at end of file +} diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp index e469b69a0bd3fe70ef0ba3b2cfb8608724d03f07..8a35f27553240e4034cc9d25f11cf73328d01080 100644 --- a/frameworks/ans/src/reminder_request_timer.cpp +++ b/frameworks/ans/src/reminder_request_timer.cpp @@ -108,8 +108,8 @@ void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) ANSR_LOGW("BootTime is illegal"); return; } - SetTriggerTimeInMilli(whenToChangeSysTime_ + (countDownTimeInSeconds_ * MILLI_SECONDS - - (static_cast(bootTime) - firstRealTimeInMilliSeconds_))); + SetTriggerTimeInMilli(whenToChangeSysTime_ + countDownTimeInSeconds_ * MILLI_SECONDS - + (static_cast(bootTime) - firstRealTimeInMilliSeconds_)); } bool ReminderRequestTimer::Marshalling(Parcel &parcel) const @@ -158,4 +158,4 @@ bool ReminderRequestTimer::ReadFromParcel(Parcel &parcel) return true; } } -} \ No newline at end of file +} diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 78fcb73054695d15309faef3b4eff73dd3b3e410..e901da196d89702d4d499b4e7c0ee7faacf6f57a 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -762,10 +762,49 @@ private: ErrCode HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply); template - bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result); + bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) + { + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; + } + + if (!reply.WriteInt32(parcelableVector.size())) { + ANS_LOGE("write ParcelableVector size failed"); + return false; + } + + for (auto &parcelable : parcelableVector) { + if (!reply.WriteStrongParcelable(parcelable)) { + ANS_LOGE("write ParcelableVector failed"); + return false; + } + } + return true; + } template - bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data); + bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) + { + int32_t infoSize = 0; + if (!data.ReadInt32(infoSize)) { + ANS_LOGE("Failed to read Parcelable size."); + return false; + } + + parcelableInfos.clear(); + infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; + for (int32_t index = 0; index < infoSize; index++) { + sptr info = data.ReadStrongParcelable(); + if (info == nullptr) { + ANS_LOGE("Failed to read Parcelable infos."); + return false; + } + parcelableInfos.emplace_back(info); + } + + return true; + } }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/include/ans_subscriber_proxy.h b/frameworks/core/include/ans_subscriber_proxy.h index 2c2d883243f931c729aad561abbbf91f323bf481..7fa46b9f27177cfb3e821f00b93c88b570f476c3 100644 --- a/frameworks/core/include/ans_subscriber_proxy.h +++ b/frameworks/core/include/ans_subscriber_proxy.h @@ -91,8 +91,23 @@ public: private: ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; + template - bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data); + bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) + { + if (!data.WriteInt32(parcelableVector.size())) { + ANS_LOGE("write ParcelableVector size failed"); + return false; + } + + for (auto &parcelable : parcelableVector) { + if (!data.WriteStrongParcelable(parcelable)) { + ANS_LOGE("write ParcelableVector failed"); + return false; + } + } + return true; + } }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index b353d675c6575344960ddb9317950d1e9b5bb00f..d34a92c4179968ae50c0687cc79111f4a6c7b890 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -1471,52 +1471,6 @@ ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParc return result; } -template -bool AnsManagerStub::WriteParcelableVector( - const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) -{ - if (!reply.WriteInt32(result)) { - ANS_LOGE("write result failed, ErrCode=%{public}d", result); - return false; - } - - if (!reply.WriteInt32(parcelableVector.size())) { - ANS_LOGE("write ParcelableVector size failed"); - return false; - } - - for (auto &parcelable : parcelableVector) { - if (!reply.WriteStrongParcelable(parcelable)) { - ANS_LOGE("write ParcelableVector failed"); - return false; - } - } - return true; -} - -template -bool AnsManagerStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - ANS_LOGE("Failed to read Parcelable size."); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadStrongParcelable(); - if (info == nullptr) { - ANS_LOGE("Failed to read Parcelable infos."); - return false; - } - parcelableInfos.emplace_back(info); - } - - return true; -} - ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply) { std::string templateName; diff --git a/frameworks/core/src/ans_subscriber_proxy.cpp b/frameworks/core/src/ans_subscriber_proxy.cpp index 96f7b9fa37e03e08f3819dc10a03102f06ec8b91..8a7a1e00344e46b4c75c3db91b993cefd4578df2 100644 --- a/frameworks/core/src/ans_subscriber_proxy.cpp +++ b/frameworks/core/src/ans_subscriber_proxy.cpp @@ -217,23 +217,6 @@ void AnsSubscriberProxy::OnCanceledList(const std::vector> &n } } -template -bool AnsSubscriberProxy::WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) -{ - if (!data.WriteInt32(parcelableVector.size())) { - ANS_LOGE("write ParcelableVector size failed"); - return false; - } - - for (auto &parcelable : parcelableVector) { - if (!data.WriteStrongParcelable(parcelable)) { - ANS_LOGE("write ParcelableVector failed"); - return false; - } - } - return true; -} - void AnsSubscriberProxy::OnUpdated(const sptr ¬ificationMap) { if (notificationMap == nullptr) { diff --git a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp index 221b168055d43b11fb39fb2f5c2aeda4dd2f0b64..294effc1b42b35a39719e8f726a9e565d70ac7a9 100644 --- a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp @@ -25,6 +25,9 @@ #include "ans_inner_errors.h" #include "ipc_types.h" #include "notification.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" #include "singleton.h" #include "notification_subscriber.h" @@ -265,7 +268,8 @@ HWTEST_F(AnsNotificationUnitAnnexTest, PublishContinuousTaskNotification_0200, F */ HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0100, Function | MediumTest | Level1) { - ReminderRequest reminder = ReminderRequest(ReminderRequest::ReminderType::TIMER); + uint64_t countDownTimeInSeconds = 0; + ReminderRequestTimer reminder = ReminderRequestTimer(countDownTimeInSeconds); ErrCode ret = ans_->PublishReminder(reminder); int errorcode = 201; EXPECT_EQ(ret, errorcode); @@ -279,7 +283,8 @@ HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0100, Function | MediumTe */ HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0200, Function | MediumTest | Level1) { - ReminderRequest reminder = ReminderRequest(ReminderRequest::ReminderType::ALARM); + std::vector daysOfWeek; + ReminderRequestAlarm reminder = ReminderRequestAlarm(0, 0, daysOfWeek); ErrCode ret = ans_->PublishReminder(reminder); int errorcode = 201; EXPECT_EQ(ret, errorcode); @@ -293,7 +298,10 @@ HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0200, Function | MediumTe */ HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0300, Function | MediumTest | Level1) { - ReminderRequest reminder = ReminderRequest(ReminderRequest::ReminderType::CALENDAR); + tm dateTime {}; + std::vector repeatMonths; + std::vector repeatDays; + ReminderRequestCalendar reminder = ReminderRequestCalendar(dateTime, repeatMonths, repeatDays); ErrCode ret = ans_->PublishReminder(reminder); int errorcode = 201; EXPECT_EQ(ret, errorcode); @@ -314,4 +322,4 @@ HWTEST_F(AnsNotificationUnitAnnexTest, CheckImageSizeForContent_0100, Function | EXPECT_EQ(ret, ERR_OK); } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index e26c341b6fe0002401de0cebd0645ece32d565ca..3d8ba0be5175218cc7f1880727d069019079626a 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -42,6 +42,16 @@ config("native_module_config") { } ohos_shared_library("notification") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_napi_path}/inner/napi_common", diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 26b5bd905aa2d1b54d4e769df15f1e09a2dc8449..c8497748781733afddf83e39c809345c3cf573a4 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -27,6 +27,16 @@ config("native_module_config") { } ohos_shared_library("notificationmanager") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_napi_path}/inner/napi_common", diff --git a/frameworks/js/napi/src/reminder/BUILD.gn b/frameworks/js/napi/src/reminder/BUILD.gn index ccfbdb0589737c6a47f7bb99a2d0b0df922ad5d5..180a6318eff9563737c959612d63e37737f626db 100644 --- a/frameworks/js/napi/src/reminder/BUILD.gn +++ b/frameworks/js/napi/src/reminder/BUILD.gn @@ -27,6 +27,16 @@ config("native_module_config") { } ohos_shared_library("reminderagent") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + include_dirs = [ "../../include", "//third_party/node/src", @@ -68,6 +78,16 @@ ohos_shared_library("reminderagent") { # used for error code ohos_shared_library("reminderagentmanager") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + include_dirs = [ "../../include", "../../include/manager", diff --git a/frameworks/js/napi/src/subscribe/BUILD.gn b/frameworks/js/napi/src/subscribe/BUILD.gn index 582c403592869e77cb9f2e877f6d0d581699237d..db4d4228806d835f9e8f34f6110a802f8d3b0850 100644 --- a/frameworks/js/napi/src/subscribe/BUILD.gn +++ b/frameworks/js/napi/src/subscribe/BUILD.gn @@ -27,6 +27,16 @@ config("native_module_config") { } ohos_shared_library("notificationsubscribe") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_napi_path}/inner/napi_common", diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 090e1998d0eb49ec3956c91e1db5d3f85085067e..edc6d381abdb228c4ab2da819810d0a849e4f315 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -26,6 +26,16 @@ config("public_ans_config") { } ohos_shared_library("libans") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + shlib_type = "sa" version_script = "libans.map" include_dirs = [ diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 682d876197a632d5163a17f9ff5c066d61f8e4fb..c39458f3d7e94493f276a182e77543997e228bb9 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -757,8 +757,8 @@ private: ErrCode FlowControl(const std::shared_ptr &record); sptr GenerateSortingMap(); - sptr GenerateBundleOption(); - sptr GenerateValidBundleOption(const sptr &bundleOption); + static sptr GenerateBundleOption(); + static sptr GenerateValidBundleOption(const sptr &bundleOption); std::string TimeToString(int64_t time); int64_t GetNowSysTime(); @@ -772,10 +772,10 @@ private: void UpdateRecentNotification(sptr ¬ification, bool isDelete, int32_t reason); void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate); - bool CheckPermission(const std::string &permission); + static bool CheckPermission(const std::string &permission); ErrCode PrepareNotificationRequest(const sptr &request); ErrCode PrepareContinuousTaskNotificationRequest(const sptr &request, const int32_t &uid); - bool GetActiveUserId(int& userId); + static bool GetActiveUserId(int& userId); void TriggerRemoveWantAgent(const sptr &request); bool CheckApiCompatibility(const sptr &bundleOption); ErrCode IsAllowedNotifySelf(const sptr &bundleOption, bool &allowed); @@ -796,7 +796,8 @@ private: const std::string &deviceId, const std::string &bundleName, sptr &request); void OnDistributedDelete( const std::string &deviceId, const std::string &bundleName, const std::string &label, int32_t id); - ErrCode GetDistributedEnableInApplicationInfo(const sptr bundleOption, bool &enable); + static ErrCode GetDistributedEnableInApplicationInfo( + const sptr bundleOption, bool &enable); bool CheckPublishWithoutApp(const int32_t userId, const sptr &request); #endif @@ -804,16 +805,16 @@ private: ErrCode GetDoNotDisturbDateByUser(const int32_t &userId, sptr &date); ErrCode SetHasPoppedDialog(const sptr bundleOption, bool hasPopped); ErrCode GetHasPoppedDialog(const sptr bundleOption, bool &hasPopped); - ErrCode GetAppTargetBundle(const sptr &bundleOption, + static ErrCode GetAppTargetBundle(const sptr &bundleOption, sptr &targetBundle); bool PublishSlotChangeCommonEvent(const sptr &bundleOption); void ReportInfoToResourceSchedule(const int32_t userId, const std::string &bundleName); int Dump(int fd, const std::vector &args) override; void GetDumpInfo(const std::vector &args, std::string &result); - void SendSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr &info, + static void SendSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr &info, ErrCode errCode); - void SendUnSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr &info); + static void SendUnSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr &info); void SendPublishHiSysEvent(const sptr &request, ErrCode errCode); void SendCancelHiSysEvent(int32_t notificationId, const std::string &label, const sptr &bundleOption, ErrCode errCode); diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 9a5cf9aee5e29648e35a9091ad612c4f79fbc82a..7b37c57a94b6766f4d3581b09f9202dd186f725f 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -137,7 +137,7 @@ public: * * @param Indicates the single instance of ans notification service. */ - void SetService(AdvancedNotificationService *advancedNotificationService); + void SetService(sptr &advancedNotificationService); bool ShouldAlert(const sptr &reminder) const; @@ -519,4 +519,4 @@ private: }; } // namespace OHOS } // namespace Notification -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_DATA_MANAGER_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_DATA_MANAGER_H diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 3ebfc47842ee530b3b09df520c02795ac47699d6..6be270eeb7ef08837cb7df3a5577c21abab2c8a0 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -598,7 +598,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( store_->UpdateOrInsert(reminder, bundleOption); } -void ReminderDataManager::SetService(AdvancedNotificationService *advancedNotificationService) +void ReminderDataManager::SetService(sptr &advancedNotificationService) { advancedNotificationService_ = advancedNotificationService; } @@ -1433,4 +1433,4 @@ void ReminderDataManager::HandleCustomButtonClick(const OHOS::EventFwk::Want &wa } } } -} \ No newline at end of file +} diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 158ac790ed14756c0a3544c5475c04ec473a1f29..c060b245ff43cd424c995643b4d537b42eab0912 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -637,13 +637,14 @@ ohos_unittest("notification_preferences_database_branch_test") { ] sources = [ + "${services_path}/ans/src/notification_preferences_database.cpp", + "${services_path}/ans/src/notification_preferences_info.cpp", "notification_preferences_database_branch_test/mock_notification_rdb_data_mgr.cpp", "notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp", ] deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", "//third_party/googletest:gtest_main", ] diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index e6f3102b4342c2d688015ac2be9bf0da2b945bef..dad1f7e8d6610d55024b990f5b6a576382a70d52 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -613,7 +613,7 @@ HWTEST_F(AnsBranchTest, AnsBranchTest_250000, Function | SmallTest | Level1) MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); - sptr targetBundle = nullptr; + sptr targetBundle(nullptr); bundleOption->SetBundleName("test"); EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_ANS_NON_SYSTEM_APP); } @@ -1128,4 +1128,4 @@ HWTEST_F(AnsBranchTest, AnsBranchTest_278000, Function | SmallTest | Level1) bundleOption, enabled), ERR_ANS_INVALID_PARAM); } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_database_branch_test/mock_notification_rdb_data_mgr.cpp b/services/ans/test/unittest/notification_preferences_database_branch_test/mock_notification_rdb_data_mgr.cpp index 61246cbbe0884d439d5acf50a37ab6a6e58c1a13..e26ed128aec6aac036be94df1678ca521684d014 100755 --- a/services/ans/test/unittest/notification_preferences_database_branch_test/mock_notification_rdb_data_mgr.cpp +++ b/services/ans/test/unittest/notification_preferences_database_branch_test/mock_notification_rdb_data_mgr.cpp @@ -61,6 +61,11 @@ void MockDeleteData(bool mockRet) namespace OHOS { namespace Notification { +NotificationDataMgr::NotificationDataMgr(const NotificationRdbConfig ¬ificationRdbConfig) + : notificationRdbConfig_(notificationRdbConfig) +{ +} + int32_t NotificationDataMgr::Init() { if (g_mockInitRet == false) { @@ -69,6 +74,14 @@ int32_t NotificationDataMgr::Init() return NativeRdb::E_OK; } +int32_t NotificationDataMgr::Destroy() +{ + if (g_mockInitRet == false) { + return NativeRdb::E_ERROR; + } + return NativeRdb::E_OK; +} + int32_t NotificationDataMgr::QueryData(const std::string &key, std::string &value) { if (g_mockQueryDataRet == false) { @@ -118,4 +131,4 @@ int32_t NotificationDataMgr::DeleteData(const std::string &key) return NativeRdb::E_OK; } } -} \ No newline at end of file +} diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index 415a4c9e0f312a45b4cec35090fb6f00fc36d709..d95b8465d63a6a95ec875fa4ded40c5df011fd51 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -226,8 +226,8 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_009, Level1) sptr reminder = new ReminderRequestTimer(10); sptr option = new NotificationBundleOption(); manager->UpdateAndSaveReminderLocked(reminder, option); - AdvancedNotificationService service; - manager->SetService(&service); + sptr service(new AdvancedNotificationService); + manager->SetService(service); manager->ShouldAlert(nullptr); manager->currentUserId_ = 0; option->SetUid(1); @@ -262,9 +262,9 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_010, Level1) */ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_011, Level1) { - sptr reminder = new ReminderRequestTimer(10); + sptr reminder(new ReminderRequestTimer(10)); reminder->SetReminderId(0); - sptr option = new NotificationBundleOption(); + sptr option(new NotificationBundleOption()); manager->notificationBundleOptionMap_[10] = option; manager->ShowReminder(reminder, true, true, true, true); reminder->SetReminderId(10); diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index fdd4bd790ebb7798b9b8d3330505c4f2c072968a..30b7b60de275e73ed7d8710368f571789cffef34 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -22,6 +22,16 @@ config("ans_distributed_config") { } ohos_shared_library("libans_distributed") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + sources = [ "src/distributed_database.cpp", "src/distributed_database_callback.cpp", diff --git a/tools/dump/BUILD.gn b/tools/dump/BUILD.gn index beda4b6c5b10ba09dc195499fee75c5b463b9072..2d9fc8396fb0eb0c183efd972c42e0bffc2ed0bd 100644 --- a/tools/dump/BUILD.gn +++ b/tools/dump/BUILD.gn @@ -23,6 +23,16 @@ config("tools_dump_config") { } ohos_executable("anm") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + stack_protector_ret = true + public_configs = [ ":tools_dump_config" ] sources = [