From 5e07d7a48c2a9bebd06e8952e19a432c18e1536d Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 15 Apr 2025 15:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- frameworks/src/app_group_observer_napi.cpp | 7 +++++-- frameworks/src/bundle_active_app_group_napi.cpp | 4 +++- frameworks/src/bundle_state_common.cpp | 7 +++++++ frameworks/src/bundle_state_query_napi.cpp | 7 +++++++ interfaces/innerkits/src/bundle_active_module_record.cpp | 1 + .../kits/bundlestats/napi/include/bundle_state_common.h | 1 + services/common/include/bundle_active_constant.h | 1 + services/common/src/bundle_active_usage_database.cpp | 6 +++++- 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/frameworks/src/app_group_observer_napi.cpp b/frameworks/src/app_group_observer_napi.cpp index a722582..2a7f231 100644 --- a/frameworks/src/app_group_observer_napi.cpp +++ b/frameworks/src/app_group_observer_napi.cpp @@ -116,8 +116,11 @@ void UvQueueWorkOnAppGroupChanged(uv_work_t *work) napi_value results[ARGS_ONE] = {nullptr}; results[PARAM_FIRST] = result; - NAPI_CALL_RETURN_VOID(callbackReceiveDataWorkerData->env, napi_call_function(callbackReceiveDataWorkerData->env, - undefined, callback, ARGS_ONE, &results[PARAM_FIRST], &resultout)); + napi_status status = napi_call_function(callbackReceiveDataWorkerData->env, + undefined, callback, ARGS_ONE, &results[PARAM_FIRST], &resultout); + if (status != napi_ok) { + GET_AND_THROW_LAST_ERROR(callbackReceiveDataWorkerData->env); + } napi_close_handle_scope(callbackReceiveDataWorkerData->env, scope); delete callbackReceiveDataWorkerData; diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 5b16dbb..620b936 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -140,6 +140,7 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) AsyncQueryAppGroupCallbackInfo *asyncCallbackInfo = nullptr; ParseQueryAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -314,6 +315,7 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) AsyncCallbackInfoSetAppGroup *asyncCallbackInfo = nullptr; ParseSetAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -422,7 +424,7 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) AsyncRegisterCallbackInfo *asyncCallbackInfo = nullptr; ParseRegisterAppGroupCallBackParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - // return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 03c240a..d69dacd 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -733,6 +733,13 @@ std::unique_ptr BundleStateCommon::HandleEventStats (long long)callbackPtr->beginTime, (long long)callbackPtr->endTime); return callbackPtr; } + +void BundleStateCommon::DeleteNapiReference(napi_env &env, napi_ref ref) +{ + if (ref != nullptr) { + napi_delete_reference(env, ref); + } +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index a4935d2..434a099 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -134,6 +134,7 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) AsyncCallbackInfoModuleRecord *asyncCallbackInfo = nullptr; ParseQueryModuleUsageRecords(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -225,6 +226,7 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) AsyncCallbackInfoIsIdleState *asyncCallbackInfo = nullptr; ParseIsIdleStateParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -368,6 +370,7 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -424,6 +427,7 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -552,6 +556,7 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfoByInterval(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -649,6 +654,7 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsage *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -748,6 +754,7 @@ napi_value QueryAppStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppStats *asyncCallbackInfo = nullptr; ParseAppStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; diff --git a/interfaces/innerkits/src/bundle_active_module_record.cpp b/interfaces/innerkits/src/bundle_active_module_record.cpp index 5326560..b4e6051 100644 --- a/interfaces/innerkits/src/bundle_active_module_record.cpp +++ b/interfaces/innerkits/src/bundle_active_module_record.cpp @@ -117,6 +117,7 @@ BundleActiveModuleRecord *BundleActiveModuleRecord::Unmarshalling(Parcel &parcel uint32_t size = parcel.ReadUint32(); result->uid_ = parcel.ReadInt32(); if (size > MAX_FORM_NUM) { + delete result; return nullptr; } diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index cd106c5..df9815d 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -110,6 +110,7 @@ public: template static void AsyncInit(napi_env env, PARAMT ¶ms, ASYNCT* &asyncCallbackInfo); + static void DeleteNapiReference(napi_env &env, napi_ref ref); }; template diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index be48f45..f4ee663 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -78,6 +78,7 @@ const int32_t FORM_LAST_TIME_COLUMN_INDEX = 7; const int32_t FORM_UID_COLUMN_INDEX = 8; const int32_t QUERY_CONDITION_VALID = 0; const int32_t QUERY_CONDITION_INVALID = -1; +const uint32_t BUNDLE_ACTIVE_DB_NAME_MAX_LENGTH = 100; const int64_t TWO_SECONDS = 2 * 1000LL; const int64_t THIRTY_MINUTE = 30 * 60 * 1000LL; const int64_t SIX_DAY_IN_MILLIS_MAX_DEBUG = 6 * 1 * 10 * 60 * 1000LL; diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 0dbf59e..8e4e74d 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -420,6 +420,10 @@ int64_t BundleActiveUsageDatabase::ParseStartTime(const string &tableName) return invalidStartTime; } string tableTime = tableName; + if (tableTime.length() > BUNDLE_ACTIVE_DB_NAME_MAX_LENGTH) { + int64_t invalidStartTime(BUNDLE_ACTIVE_FAIL); + return invalidStartTime; + } for (uint32_t i = 0; i < tableTime.length(); i++) { if (tableTime[i] >= '0' && tableTime[i] <= '9') { tableTime = tableTime.substr(i); @@ -1082,7 +1086,7 @@ void BundleActiveUsageDatabase::FlushEventInfo(uint32_t databaseType, BundleActi int64_t eventTableTime = ParseStartTime(eventTableName_); int64_t outRowId = BUNDLE_ACTIVE_FAIL; std::vector valuesBuckets; - for (int32_t i = 0; i < stats.events_.Size(); i++) { + for (uint32_t i = 0; i < stats.events_.Size(); i++) { NativeRdb::ValuesBucket valuesBucket; valuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, stats.userId_); valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, stats.events_.events_.at(i).bundleName_); -- Gitee