diff --git a/frameworks/ans/src/notification_local_live_view_button.cpp b/frameworks/ans/src/notification_local_live_view_button.cpp index 81d163d5172dc3e92962acafd51d732f81b50221..ae93977ac50f162791aeefb95e0bbeff6a255d53 100644 --- a/frameworks/ans/src/notification_local_live_view_button.cpp +++ b/frameworks/ans/src/notification_local_live_view_button.cpp @@ -16,6 +16,7 @@ #include "notification_local_live_view_button.h" #include +#include #include // for basic_string, operator+, basic_string<>... #include // for shared_ptr, shared_ptr<>::element_type #include @@ -172,6 +173,7 @@ NotificationLocalLiveViewButton *NotificationLocalLiveViewButton::FromJson(const auto pIcon = AnsImageUtil::UnPackImage(iconObj.get()); if (pIcon == nullptr) { ANS_LOGE("Failed to parse button icon"); + delete button; return nullptr; } button->buttonIcons_.emplace_back(pIcon); @@ -257,10 +259,19 @@ bool NotificationLocalLiveViewButton::ReadFromParcel(Parcel &parcel) ANS_LOGE("Failed to read button names"); return false; } + if (iconsResource.size(); resource->bundleName = iconsResource[RESOURCE_BUNDLENAME_INDEX]; resource->moduleName = iconsResource[RESOURCE_MODULENAME_INDEX]; - resource->id = std::stoi(iconsResource[RESOURCE_ID_INDEX]); + try { + resource->id = std::stoi(iconsResource[RESOURCE_ID_INDEX]); + } catch (...) { + ANS_LOGE(AAFwkTag::APPKIT, "stoi(%(public)s) failed", iconsResource[RESOURCE_ID_INDEX].c_str()); + return false; + } buttonIconsResource_.emplace_back(resource); } diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 90ce7593486c13fca27bddeca10d05d167fa7a98..b3b5db337d3334f4fcf866446ffa062280837c0a 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -24,6 +24,7 @@ #include "refbase.h" #include "want_agent_helper.h" #include "want_params_wrapper.h" +#include #include namespace OHOS { @@ -1502,11 +1503,37 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) return false; } - slotType_ = static_cast(parcel.ReadInt32()); - groupAlertType_ = static_cast(parcel.ReadInt32()); - visiblenessType_ = static_cast(parcel.ReadInt32()); - badgeStyle_ = static_cast(parcel.ReadInt32()); - notificationContentType_ = static_cast(parcel.ReadInt32()); + int32_t slotTypeValue = parcel.ReadInt32(); + if (slotTypeValue < 0 || slotTypeValue >= NotificationConstant::SlotType.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", slotTypeValue); + return false; + } + slotType_ = static_cast(slotTypeValue); + int32_t groupAlertTypeValue = parcel.ReadInt32(); + if (groupAlertTypeValue < 0 || groupAlertTypeValue >= NotificationRequest::GroupAlertType.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", groupAlertTypeValue); + return false; + } + groupAlertType_ = static_cast(groupAlertTypeValue); + int32_t visiblenessTypeValue = parcel.ReadInt32(); + if (visiblenessTypeValue < 0 || visiblenessTypeValue >= NotificationConstant::VisiblenessType.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", visiblenessTypeValue); + return false; + } + visiblenessType_ = static_cast(visiblenessTypeValue); + int32_t badgeStyleValue = parcel.ReadInt32(); + if (badgeStyleValue < 0 || badgeStyleValue >= NotificationRequest::BadgeStyle.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", badgeStyleValue); + return false; + } + badgeStyle_ = static_cast(badgeStyleValue); + int32_t notificationContentTypeValue = parcel.ReadInt32(); + if (notificationContentTypeValue <= NotificationContent::Type.NONE || + notificationContentTypeValue >= NotificationContent::Type.ILLEGAL_TYPE) { + ANS_LOGE("Invalid slot type value :%d", otificationContentTypeValue); + return false; + } + notificationContentType_ = static_cast(notificationContentTypeValue); showDeliveryTime_ = parcel.ReadBool(); tapDismissed_ = parcel.ReadBool(); @@ -2255,7 +2282,7 @@ bool NotificationRequest::ConvertJsonToNotificationDistributedOptions( target->distributedOptions_ = *pOpt; } } - + delete pOpt; return true; } diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 5fec6397ba327d1262d92296dda8ca57b6bb7cdf..507408478ab678b13e975451f2c9a54e7d6e2e6e 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -65,6 +65,7 @@ public: LIVE_VIEW, // the notification type is live view CUSTOMER_SERVICE, // the notification type is customer service EMERGENCY_INFORMATION, // the notification type is emergency information + ILLEGAL_TYPE, // invalid type,it is used as the upper limit of the enumerated value }; enum ReminderFlag { @@ -94,7 +95,12 @@ public: /** * notifications are not displayed on the lock screen. */ - SECRET + SECRET, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; enum class DoNotDisturbType { diff --git a/interfaces/inner_api/notification_content.h b/interfaces/inner_api/notification_content.h index 3d68945a8a7af4c24b23f5605dde20a76365facb..836c0e80d023b5f1e0a4f7bf451534aee9807bdf 100644 --- a/interfaces/inner_api/notification_content.h +++ b/interfaces/inner_api/notification_content.h @@ -75,7 +75,12 @@ public: * Indicates notifications that include a live view. * Such notifications are created using NotificationLiveViewContent. */ - LIVE_VIEW + LIVE_VIEW, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; /** diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 541f8529434e844b219a1884f67dc058e02a9b52..b04f968556df3b702ca771d16b50a9d30ae9ef0a 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -64,7 +64,12 @@ public: /** * displayed as a small icon. */ - LITTLE + LITTLE, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; enum class GroupAlertType { @@ -82,7 +87,12 @@ public: * the overview notification has sound or vibration but child notifications are muted (no sound or vibration) * in a group if sound or vibration is enabled for the associated NotificationSlot objects. */ - OVERVIEW + OVERVIEW, + /** + * invalid type + * It is used as the upper limit of the enumerated value. + */ + ILLEGAL_TYPE }; /**