diff --git a/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp b/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp index 7dbde997bb910fd4490bd510bcee1cfda490e0c4..ed6f85f5eadbeec67143b2c0acc107b641227136 100644 --- a/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp +++ b/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp @@ -30,10 +30,10 @@ bool HapTokenInfoForSyncParcel::Marshalling(Parcel& out) const out.WriteParcelable(&baseInfoParcel); const std::vector& permStateList = this->hapTokenInfoForSyncParams.permStateList; - int32_t permStateListSize = static_cast(permStateList.size()); - RETURN_IF_FALSE(out.WriteInt32(permStateListSize)); - RETURN_IF_FALSE((permStateListSize <= MAX_PERMLIST_SIZE)); - for (int i = 0; i < permStateListSize; i++) { + uint32_t permStateListSize = permStateList.size(); + RETURN_IF_FALSE(permStateListSize <= MAX_PERMLIST_SIZE); + RETURN_IF_FALSE(out.WriteUint32(permStateListSize)); + for (uint32_t i = 0; i < permStateListSize; i++) { PermissionStateFullParcel permStateParcel; permStateParcel.permStatFull = permStateList[i]; out.WriteParcelable(&permStateParcel); @@ -53,9 +53,10 @@ HapTokenInfoForSyncParcel* HapTokenInfoForSyncParcel::Unmarshalling(Parcel& in) RELEASE_IF_FALSE(baseInfoParcel != nullptr, hapTokenInfoForSyncParcel); hapTokenInfoForSyncParcel->hapTokenInfoForSyncParams.baseInfo = baseInfoParcel->hapTokenInfoParams; - int permStateListSize; - RELEASE_IF_FALSE(in.ReadInt32(permStateListSize), hapTokenInfoForSyncParcel); - for (int i = 0; i < permStateListSize; i++) { + uint32_t permStateListSize; + RELEASE_IF_FALSE(in.ReadUint32(permStateListSize), hapTokenInfoForSyncParcel); + RELEASE_IF_FALSE((permStateListSize <= MAX_PERMLIST_SIZE), hapTokenInfoForSyncParcel); + for (uint32_t i = 0; i < permStateListSize; i++) { sptr permissionStateParcel = in.ReadParcelable(); RELEASE_IF_FALSE(permissionStateParcel != nullptr, hapTokenInfoForSyncParcel); hapTokenInfoForSyncParcel->hapTokenInfoForSyncParams.permStateList.emplace_back( diff --git a/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp b/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp index 0ef3ca1979156942bfb17ffa5a5303382ff2a694..d380db591eed3f442ded813b8fbb849233f649bf 100644 --- a/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp +++ b/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp @@ -30,10 +30,10 @@ bool NativeTokenInfoForSyncParcel::Marshalling(Parcel& out) const RETURN_IF_FALSE(out.WriteParcelable(&baseInfoParcel)); const std::vector& permStateList = this->nativeTokenInfoForSyncParams.permStateList; - int32_t permStateListSize = static_cast(permStateList.size()); - RETURN_IF_FALSE(out.WriteInt32(permStateListSize)); - RETURN_IF_FALSE((permStateListSize <= MAX_PERMLIST_SIZE)); - for (int i = 0; i < permStateListSize; i++) { + uint32_t permStateListSize = permStateList.size(); + RETURN_IF_FALSE(permStateListSize <= MAX_PERMLIST_SIZE); + RETURN_IF_FALSE(out.WriteUint32(permStateListSize)); + for (uint32_t i = 0; i < permStateListSize; i++) { PermissionStateFullParcel permStateParcel; permStateParcel.permStatFull = permStateList[i]; RETURN_IF_FALSE(out.WriteParcelable(&permStateParcel)); @@ -53,9 +53,10 @@ NativeTokenInfoForSyncParcel* NativeTokenInfoForSyncParcel::Unmarshalling(Parcel RELEASE_IF_FALSE(baseInfoParcel != nullptr, nativeTokenInfoForSyncParcel); nativeTokenInfoForSyncParcel->nativeTokenInfoForSyncParams.baseInfo = baseInfoParcel->nativeTokenInfoParams; - int permStateListSize; - RELEASE_IF_FALSE(in.ReadInt32(permStateListSize), nativeTokenInfoForSyncParcel); - for (int i = 0; i < permStateListSize; i++) { + uint32_t permStateListSize; + RELEASE_IF_FALSE(in.ReadUint32(permStateListSize), nativeTokenInfoForSyncParcel); + RELEASE_IF_FALSE(permStateListSize <= MAX_PERMLIST_SIZE, nativeTokenInfoForSyncParcel); + for (uint32_t i = 0; i < permStateListSize; i++) { sptr permissionStateParcel = in.ReadParcelable(); RELEASE_IF_FALSE(permissionStateParcel != nullptr, nativeTokenInfoForSyncParcel); nativeTokenInfoForSyncParcel->nativeTokenInfoForSyncParams.permStateList.emplace_back( diff --git a/frameworks/accesstoken/src/native_token_info_parcel.cpp b/frameworks/accesstoken/src/native_token_info_parcel.cpp index 06ff8df1492827e25f39e6893741a1aaae7b9bb9..c07b33643a95859a361f443615eef10dcb69030e 100644 --- a/frameworks/accesstoken/src/native_token_info_parcel.cpp +++ b/frameworks/accesstoken/src/native_token_info_parcel.cpp @@ -32,21 +32,21 @@ bool NativeTokenInfoParcel::Marshalling(Parcel& out) const RETURN_IF_FALSE(out.WriteUint32(this->nativeTokenInfoParams.tokenID)); RETURN_IF_FALSE(out.WriteUint32(this->nativeTokenInfoParams.tokenAttr)); - if ((this->nativeTokenInfoParams.dcap).size() > INT32_MAX) { + if ((this->nativeTokenInfoParams.dcap).size() > MAX_DCAP_SIZE) { return false; } - int32_t dcapSize = static_cast((this->nativeTokenInfoParams.dcap).size()); - RETURN_IF_FALSE(out.WriteInt32(dcapSize)); + uint32_t dcapSize = (this->nativeTokenInfoParams.dcap).size(); + RETURN_IF_FALSE(out.WriteUint32(dcapSize)); for (const auto& dcapItem : this->nativeTokenInfoParams.dcap) { RETURN_IF_FALSE(out.WriteString(dcapItem)); } - if ((this->nativeTokenInfoParams.nativeAcls).size() > INT32_MAX) { + if ((this->nativeTokenInfoParams.nativeAcls).size() > MAX_ACL_SIZE) { return false; } - int32_t nativeAclSize = static_cast((this->nativeTokenInfoParams.nativeAcls).size()); - RETURN_IF_FALSE(out.WriteInt32(nativeAclSize)); + uint32_t nativeAclSize = (this->nativeTokenInfoParams.nativeAcls).size(); + RETURN_IF_FALSE(out.WriteUint32(nativeAclSize)); for (const auto& item : this->nativeTokenInfoParams.nativeAcls) { RETURN_IF_FALSE(out.WriteString(item)); @@ -73,8 +73,9 @@ NativeTokenInfoParcel* NativeTokenInfoParcel::Unmarshalling(Parcel& in) RELEASE_IF_FALSE(in.ReadUint32(nativeTokenInfoParcel->nativeTokenInfoParams.tokenID), nativeTokenInfoParcel); RELEASE_IF_FALSE(in.ReadUint32(nativeTokenInfoParcel->nativeTokenInfoParams.tokenAttr), nativeTokenInfoParcel); - int32_t dcapSize; - RELEASE_IF_FALSE(in.ReadInt32(dcapSize), nativeTokenInfoParcel); + uint32_t dcapSize; + RELEASE_IF_FALSE(in.ReadUint32(dcapSize), nativeTokenInfoParcel); + RELEASE_IF_FALSE(dcapSize <= MAX_DCAP_SIZE, nativeTokenInfoParcel); for (int32_t i = 0; i < dcapSize; i++) { std::string dcapsItem; @@ -82,8 +83,9 @@ NativeTokenInfoParcel* NativeTokenInfoParcel::Unmarshalling(Parcel& in) nativeTokenInfoParcel->nativeTokenInfoParams.dcap.emplace_back(dcapsItem); } - int32_t nativeAclSize; - RELEASE_IF_FALSE(in.ReadInt32(nativeAclSize), nativeTokenInfoParcel); + uint32_t nativeAclSize; + RELEASE_IF_FALSE(in.ReadUint32(nativeAclSize), nativeTokenInfoParcel); + RELEASE_IF_FALSE(nativeAclSize <= MAX_ACL_SIZE, nativeTokenInfoParcel); for (int32_t i = 0; i < nativeAclSize; i++) { std::string item; diff --git a/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp b/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp index 8555df3533764777dee7971f36034edad0b48a5d..31d3aa8c661484340dc7b9919aac4bc1cb761659 100644 --- a/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp +++ b/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp @@ -21,11 +21,13 @@ namespace Security { namespace AccessToken { bool PermStateChangeScopeParcel::Marshalling(Parcel& out) const { + RETURN_IF_FALSE(this->scope.tokenIDs.size() <= TOKENIDS_LIST_SIZE_MAX); RETURN_IF_FALSE(out.WriteUint32((this->scope.tokenIDs.size()))); for (const auto& tokenID : this->scope.tokenIDs) { RETURN_IF_FALSE(out.WriteUint32(tokenID)); } + RETURN_IF_FALSE(this->scope.permList.size() <= PERMS_LIST_SIZE_MAX); RETURN_IF_FALSE(out.WriteUint32((this->scope.permList.size()))); for (const auto& permissionName : this->scope.permList) { RETURN_IF_FALSE(out.WriteString(permissionName)); diff --git a/frameworks/accesstoken/src/permission_state_full_parcel.cpp b/frameworks/accesstoken/src/permission_state_full_parcel.cpp index 364676c233afd4be7b144fd27fb560e2e261fbaf..22425a99e0f2c0dce8df46d31243301aadc6766e 100644 --- a/frameworks/accesstoken/src/permission_state_full_parcel.cpp +++ b/frameworks/accesstoken/src/permission_state_full_parcel.cpp @@ -24,17 +24,17 @@ bool PermissionStateFullParcel::Marshalling(Parcel& out) const RETURN_IF_FALSE(out.WriteString(this->permStatFull.permissionName)); RETURN_IF_FALSE(out.WriteBool(this->permStatFull.isGeneral)); - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->permStatFull.resDeviceID.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->permStatFull.resDeviceID.size())); for (auto devId : this->permStatFull.resDeviceID) { RETURN_IF_FALSE(out.WriteString(devId)); } - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->permStatFull.grantStatus.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->permStatFull.grantStatus.size())); for (auto grantStat : this->permStatFull.grantStatus) { RETURN_IF_FALSE(out.WriteInt32(grantStat)); } - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->permStatFull.grantFlags.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->permStatFull.grantFlags.size())); for (auto grantFlag : this->permStatFull.grantFlags) { RETURN_IF_FALSE(out.WriteInt32(grantFlag)); } @@ -51,25 +51,28 @@ PermissionStateFullParcel* PermissionStateFullParcel::Unmarshalling(Parcel& in) RELEASE_IF_FALSE(in.ReadString(permissionStateParcel->permStatFull.permissionName), permissionStateParcel); RELEASE_IF_FALSE(in.ReadBool(permissionStateParcel->permStatFull.isGeneral), permissionStateParcel); - int resIdSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(resIdSize), permissionStateParcel); - for (int i = 0; i < resIdSize; i++) { + uint32_t resIdSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(resIdSize), permissionStateParcel); + RELEASE_IF_FALSE(resIdSize <= MAX_DEVICE_ID_SIZE, permissionStateParcel); + for (uint32_t i = 0; i < resIdSize; i++) { std::string resId; RELEASE_IF_FALSE(in.ReadString(resId), permissionStateParcel); permissionStateParcel->permStatFull.resDeviceID.emplace_back(resId); } - int grantStatsSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(grantStatsSize), permissionStateParcel); - for (int i = 0; i < grantStatsSize; i++) { + uint32_t grantStatsSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(grantStatsSize), permissionStateParcel); + RELEASE_IF_FALSE(grantStatsSize <= MAX_DEVICE_ID_SIZE, permissionStateParcel); + for (uint32_t i = 0; i < grantStatsSize; i++) { int grantStat; RELEASE_IF_FALSE(in.ReadInt32(grantStat), permissionStateParcel); permissionStateParcel->permStatFull.grantStatus.emplace_back(grantStat); } - int grantFlagSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(grantFlagSize), permissionStateParcel); - for (int i = 0; i < grantFlagSize; i++) { + uint32_t grantFlagSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(grantFlagSize), permissionStateParcel); + RELEASE_IF_FALSE(grantFlagSize <= MAX_DEVICE_ID_SIZE, permissionStateParcel); + for (uint32_t i = 0; i < grantFlagSize; i++) { int flag; RELEASE_IF_FALSE(in.ReadInt32(flag), permissionStateParcel); permissionStateParcel->permStatFull.grantFlags.emplace_back(flag); diff --git a/frameworks/common/include/parcel_utils.h b/frameworks/common/include/parcel_utils.h index fcd97ae8280dde5ba086d31bba28f7672b4159aa..f93545ce14e77e767c59718559b1c4fa10d9b57f 100644 --- a/frameworks/common/include/parcel_utils.h +++ b/frameworks/common/include/parcel_utils.h @@ -16,6 +16,10 @@ #ifndef PARCEL_UTILS_H #define PARCEL_UTILS_H #define MAX_PERMLIST_SIZE 256 +#define MAX_DCAP_SIZE 32 +#define MAX_ACL_SIZE 64 +#define MAX_DEVICE_ID_SIZE 1024 +#define MAX_RECORD_SIZE 10 * 1024 * 1024 namespace OHOS { namespace Security { namespace AccessToken { diff --git a/frameworks/privacy/src/bundle_used_record_parcel.cpp b/frameworks/privacy/src/bundle_used_record_parcel.cpp index 65d470af3468f9c3a01d1357fbd65cb5b36be3fd..de25d3f81d314566b1f8d80ce6f09f78859fb888 100644 --- a/frameworks/privacy/src/bundle_used_record_parcel.cpp +++ b/frameworks/privacy/src/bundle_used_record_parcel.cpp @@ -28,7 +28,7 @@ bool BundleUsedRecordParcel::Marshalling(Parcel& out) const RETURN_IF_FALSE(out.WriteString(this->bundleRecord.deviceId)); RETURN_IF_FALSE(out.WriteString(this->bundleRecord.bundleName)); - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->bundleRecord.permissionRecords.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->bundleRecord.permissionRecords.size())); for (const auto& permRecord : this->bundleRecord.permissionRecords) { PermissionUsedRecordParcel permRecordParcel; permRecordParcel.permissionRecord = permRecord; @@ -49,9 +49,10 @@ BundleUsedRecordParcel* BundleUsedRecordParcel::Unmarshalling(Parcel& in) RELEASE_IF_FALSE(in.ReadString(bundleRecordParcel->bundleRecord.deviceId), bundleRecordParcel); RELEASE_IF_FALSE(in.ReadString(bundleRecordParcel->bundleRecord.bundleName), bundleRecordParcel); - int32_t permRecordSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(permRecordSize), bundleRecordParcel); - for (int32_t i = 0; i < permRecordSize; i++) { + uint32_t permRecordSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(permRecordSize), bundleRecordParcel); + RELEASE_IF_FALSE(permRecordSize < MAX_RECORD_SIZE, bundleRecordParcel); + for (uint32_t i = 0; i < permRecordSize; i++) { sptr permRecord = in.ReadParcelable(); RELEASE_IF_FALSE(permRecord != nullptr, bundleRecordParcel); bundleRecordParcel->bundleRecord.permissionRecords.emplace_back(permRecord->permissionRecord); diff --git a/frameworks/privacy/src/permission_used_record_parcel.cpp b/frameworks/privacy/src/permission_used_record_parcel.cpp index cda521c31e6b2b3de1266ab9e7ee8b3850ddf5f2..a2e62f3fd2c554f1482b033a95ed39cf2e45e337 100644 --- a/frameworks/privacy/src/permission_used_record_parcel.cpp +++ b/frameworks/privacy/src/permission_used_record_parcel.cpp @@ -30,14 +30,14 @@ bool PermissionUsedRecordParcel::Marshalling(Parcel& out) const RETURN_IF_FALSE(out.WriteInt64(this->permissionRecord.lastRejectTime)); RETURN_IF_FALSE(out.WriteInt64(this->permissionRecord.lastAccessDuration)); - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->permissionRecord.accessRecords.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->permissionRecord.accessRecords.size())); for (const auto& accRecord : this->permissionRecord.accessRecords) { UsedRecordDetailParcel detailParcel; detailParcel.detail = accRecord; out.WriteParcelable(&detailParcel); } - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->permissionRecord.rejectRecords.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->permissionRecord.rejectRecords.size())); for (const auto& rejRecord : this->permissionRecord.rejectRecords) { UsedRecordDetailParcel detailParcel; detailParcel.detail = rejRecord; @@ -60,17 +60,19 @@ PermissionUsedRecordParcel* PermissionUsedRecordParcel::Unmarshalling(Parcel& in RELEASE_IF_FALSE(in.ReadInt64(permissionRecordParcel->permissionRecord.lastRejectTime), permissionRecordParcel); RELEASE_IF_FALSE(in.ReadInt64(permissionRecordParcel->permissionRecord.lastAccessDuration), permissionRecordParcel); - int32_t accRecordSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(accRecordSize), permissionRecordParcel); - for (int32_t i = 0; i < accRecordSize; i++) { + uint32_t accRecordSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(accRecordSize), permissionRecordParcel); + RELEASE_IF_FALSE(accRecordSize <= MAX_RECORD_SIZE, permissionRecordParcel); + for (uint32_t i = 0; i < accRecordSize; i++) { sptr detailParcel = in.ReadParcelable(); RELEASE_IF_FALSE(detailParcel != nullptr, permissionRecordParcel); permissionRecordParcel->permissionRecord.accessRecords.emplace_back(detailParcel->detail); } - int32_t rejRecordSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(rejRecordSize), permissionRecordParcel); - for (int32_t i = 0; i < rejRecordSize; i++) { + uint32_t rejRecordSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(rejRecordSize), permissionRecordParcel); + RELEASE_IF_FALSE(rejRecordSize <= MAX_RECORD_SIZE, permissionRecordParcel); + for (uint32_t i = 0; i < rejRecordSize; i++) { sptr detailParcel = in.ReadParcelable(); RELEASE_IF_FALSE(detailParcel != nullptr, permissionRecordParcel); permissionRecordParcel->permissionRecord.rejectRecords.emplace_back(detailParcel->detail); diff --git a/frameworks/privacy/src/permission_used_request_parcel.cpp b/frameworks/privacy/src/permission_used_request_parcel.cpp index 51a33b0cb68e0e6e586d3d019b516ff505c9e3e3..4f4a3fb4d07b40a8efeb3466677b1e4410c83765 100644 --- a/frameworks/privacy/src/permission_used_request_parcel.cpp +++ b/frameworks/privacy/src/permission_used_request_parcel.cpp @@ -26,7 +26,7 @@ bool PermissionUsedRequestParcel::Marshalling(Parcel& out) const RETURN_IF_FALSE(out.WriteString(this->request.deviceId)); RETURN_IF_FALSE(out.WriteString(this->request.bundleName)); - RETURN_IF_FALSE(out.WriteInt32((int32_t)(this->request.permissionList.size()))); + RETURN_IF_FALSE(out.WriteUint32(this->request.permissionList.size())); for (const auto& perm : this->request.permissionList) { RETURN_IF_FALSE(out.WriteString(perm)); } @@ -48,9 +48,10 @@ PermissionUsedRequestParcel* PermissionUsedRequestParcel::Unmarshalling(Parcel& RELEASE_IF_FALSE(in.ReadString(requestParcel->request.deviceId), requestParcel); RELEASE_IF_FALSE(in.ReadString(requestParcel->request.bundleName), requestParcel); - int32_t permSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(permSize), requestParcel); - for (int32_t i = 0; i < permSize; i++) { + uint32_t permSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(permSize), requestParcel); + RELEASE_IF_FALSE(permSize <= MAX_PERMLIST_SIZE, requestParcel); + for (uint32_t i = 0; i < permSize; i++) { std::string perm; RELEASE_IF_FALSE(in.ReadString(perm), requestParcel); requestParcel->request.permissionList.emplace_back(perm); diff --git a/frameworks/privacy/src/permission_used_result_parcel.cpp b/frameworks/privacy/src/permission_used_result_parcel.cpp index dbbe648fa49c7e9073ef14673a779c576e48b19f..a82eef5c97424dc5a1a4506181ab1913b355e30c 100644 --- a/frameworks/privacy/src/permission_used_result_parcel.cpp +++ b/frameworks/privacy/src/permission_used_result_parcel.cpp @@ -45,9 +45,10 @@ PermissionUsedResultParcel* PermissionUsedResultParcel::Unmarshalling(Parcel& in RELEASE_IF_FALSE(in.ReadInt64(resultParcel->result.beginTimeMillis), resultParcel); RELEASE_IF_FALSE(in.ReadInt64(resultParcel->result.endTimeMillis), resultParcel); - int32_t bundResponseSize = 0; - RELEASE_IF_FALSE(in.ReadInt32(bundResponseSize), resultParcel); - for (int32_t i = 0; i < bundResponseSize; i++) { + uint32_t bundResponseSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(bundResponseSize), resultParcel); + RELEASE_IF_FALSE(bundResponseSize <= MAX_RECORD_SIZE, resultParcel); + for (uint32_t i = 0; i < bundResponseSize; i++) { sptr bunRecordParcel = in.ReadParcelable(); RELEASE_IF_FALSE(bunRecordParcel != nullptr, resultParcel); resultParcel->result.bundleRecords.emplace_back(bunRecordParcel->bundleRecord); diff --git a/services/tokensyncmanager/src/remote/soft_bus_channel.cpp b/services/tokensyncmanager/src/remote/soft_bus_channel.cpp index d4cdeb052fed6bc97a953bd5ef0c6ff12a26822e..0cb49bed32f6cc1296ae877fcceb1844924631cb 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_channel.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_channel.cpp @@ -134,7 +134,7 @@ std::string SoftBusChannel::ExecuteCommand(const std::string &commandName, const ACCESSTOKEN_LOG_DEBUG(LABEL, "generated message uuid: %{public}s", uuid.c_str()); int len = (signed)(RPC_TRANSFER_HEAD_BYTES_LENGTH + jsonPayload.length()); - unsigned char *buf = new unsigned char[len + 1]; + unsigned char *buf = new (std::nothrow) unsigned char[len + 1]; if (buf == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", len); return ""; @@ -261,7 +261,7 @@ std::string SoftBusChannel::Decompress(const unsigned char *bytes, const int len { ACCESSTOKEN_LOG_DEBUG(LABEL, "input length: %{public}d", length); uLong len = RPC_TRANSFER_BYTES_MAX_LENGTH; - unsigned char *buf = new unsigned char[len + 1]; + unsigned char *buf = new (std::nothrow) unsigned char[len + 1]; if (buf == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory!"); return ""; @@ -350,7 +350,7 @@ void SoftBusChannel::HandleRequest(int session, const std::string &id, const std jsonPayload.c_str()); int sendlen = (signed)(RPC_TRANSFER_HEAD_BYTES_LENGTH + jsonPayload.length()); - unsigned char *sendbuf = new unsigned char[sendlen + 1]; + unsigned char *sendbuf = new (std::nothrow) unsigned char[sendlen + 1]; if (sendbuf == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", sendlen); return; @@ -376,7 +376,7 @@ void SoftBusChannel::HandleRequest(int session, const std::string &id, const std // send result back std::string resultJsonPayload = command->ToJsonPayload(); int len = (signed)(RPC_TRANSFER_HEAD_BYTES_LENGTH + resultJsonPayload.length()); - unsigned char *buf = new unsigned char[len + 1]; + unsigned char *buf = new (std::nothrow) unsigned char[len + 1]; if (buf == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", len); return; diff --git a/services/tokensyncmanager/src/remote/soft_bus_manager.cpp b/services/tokensyncmanager/src/remote/soft_bus_manager.cpp index c1bd1344ab6f3c09501cf11b309fe75e17061881..d1e7556784de32349292a07b2a33a444d2d1314b 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_manager.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_manager.cpp @@ -328,7 +328,7 @@ std::string SoftBusManager::GetUniqueDeviceIdByNodeId(const std::string &nodeId) std::string SoftBusManager::GetUuidByNodeId(const std::string &nodeId) const { - uint8_t *info = new uint8_t[UDID_MAX_LENGTH + 1]; + uint8_t *info = new (std::nothrow) uint8_t[UDID_MAX_LENGTH + 1]; if (info == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", UDID_MAX_LENGTH); return ""; @@ -350,7 +350,7 @@ std::string SoftBusManager::GetUuidByNodeId(const std::string &nodeId) const std::string SoftBusManager::GetUdidByNodeId(const std::string &nodeId) const { - uint8_t *info = new uint8_t[UDID_MAX_LENGTH + 1]; + uint8_t *info = new (std::nothrow) uint8_t[UDID_MAX_LENGTH + 1]; if (info == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "no enough memory: %{public}d", UDID_MAX_LENGTH); return "";