diff --git a/frameworks/src/app_group_observer_napi.cpp b/frameworks/src/app_group_observer_napi.cpp index a722582ba7e878fdd378564afbdaed7a93d3703b..2a7f231a79d344a9d48c0fd773add75b67c25a07 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 5b16dbbc172ff2e67c3f49178b20f1339a1c7768..620b936890928f399ba85370d4502281f0bc8dc9 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 03c240ad422fa46ed926263a4813094905f7043f..d69dacdb1caf0c34f152b26a0ca12251d41504f1 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 a4935d2ec2a3b8237c9da0a093f29920cabc45aa..434a09992b699f97fa5b354c15e73fc95c322d24 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 53265608e5d40000df04c95ffae33c2c4cc9cf53..b4e6051f804dd32fea47a4661a01e01f4b8319fa 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 cd106c5b14e7d9ffc8eef3e922f50bf1f168f246..df9815dc892003188888e6d207d061b7f17e205b 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 be48f45fdf83cc094e2b4d3003ec508fcf308061..f4ee663ffe28230c38903f03016b680bdc78798b 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 52842eebc08a40c1782232e86ae2b0ac4679b491..cf03ac8bdbd0f73124ba3344644e7c378ddeec9c 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -424,6 +424,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); @@ -1377,7 +1381,7 @@ void BundleActiveUsageDatabase::UpdateBundleUsageData(int32_t databaseType, Bund int32_t bundleStatsSize = 0; vector bundleActivePackageStats = QueryDatabaseUsageStats(databaseType, 0, MAX_END_TIME, stats.userId_, ""); - for (int32_t i = 0; i < bundleActivePackageStats.size(); i++) { + for (uint32_t i = 0; i < bundleActivePackageStats.size(); i++) { std::map>::iterator iter = stats.bundleStats_.find(bundleActivePackageStats[i].bundleName_ + to_string( bundleActivePackageStats[i].uid_));