From d8dd57406369e90fac2af96caca08466c9971048 Mon Sep 17 00:00:00 2001 From: caihaoting Date: Fri, 15 Nov 2024 18:01:46 +0800 Subject: [PATCH] fix safety alarm Signed-off-by: caihaoting --- .../libs/distributeddb/common/src/json_object.cpp | 12 ++++++++++++ .../storage/src/sqlite/sqlite_utils_extend.cpp | 2 -- .../distributeddb/storage/src/storage_engine.cpp | 12 ++++++------ .../syncer/src/cloud/cloud_db_proxy.cpp | 12 ++++-------- .../distributeddb/syncer/src/cloud/cloud_db_proxy.h | 4 ++-- .../distributeddb/syncer/src/cloud/cloud_syncer.h | 2 +- .../syncer/src/cloud/cloud_syncer_extend.cpp | 2 +- .../device/singlever/single_ver_data_sync_extend.cpp | 1 - 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/frameworks/libs/distributeddb/common/src/json_object.cpp b/frameworks/libs/distributeddb/common/src/json_object.cpp index 6dfa9356f19..252459f76d3 100644 --- a/frameworks/libs/distributeddb/common/src/json_object.cpp +++ b/frameworks/libs/distributeddb/common/src/json_object.cpp @@ -421,6 +421,10 @@ int JsonObject::GetArrayContentOfStringOrStringArray(const FieldPath &inPath, LOGE("[Json][GetArrayContent] Not an array."); return -E_NOT_SUPPORT; } + if (valueNode.size() > DBConstant::MAX_VALUE_SIZE) { + LOGE("[Json][GetArrayContent] Exceeds max value size."); + return -E_NOT_SUPPORT; + } for (uint32_t index = 0; index < valueNode.size(); index++) { const Json::Value &eachArrayItem = valueNode[index]; if (eachArrayItem.isString()) { @@ -601,6 +605,10 @@ int JsonObject::GetStringArrayContentByJsonValue(const Json::Value &value, LOGE("[Json][GetStringArrayByValue] Not an array."); return -E_NOT_SUPPORT; } + if (value.size() > DBConstant::MAX_VALUE_SIZE) { + LOGE("[Json][GetStringArrayByValue] Exceeds max value size."); + return -E_NOT_SUPPORT; + } for (uint32_t index = 0; index < value.size(); index++) { const Json::Value &eachArrayItem = value[index]; if (!eachArrayItem.isString()) { @@ -738,6 +746,10 @@ int JsonObject::GetObjectArrayByFieldPath(const FieldPath &inPath, std::vector DBConstant::MAX_VALUE_SIZE) { + LOGE("[Json][GetValue] Exceeds max value size."); + return -E_NOT_PERMIT; + } for (Json::ArrayIndex i = 0; i < valueNode.size(); ++i) { outArray.emplace_back(JsonObject(valueNode[i])); } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils_extend.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils_extend.cpp index 0b98cf2cfd4..194fd2985e9 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils_extend.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils_extend.cpp @@ -71,7 +71,6 @@ constexpr int VALUE_CACHE_ID = -429938; void ValueParseCacheFree(ValueParseCache *inCache) { delete inCache; - inCache = nullptr; } // We don't use cache array since we only cache value column of sqlite table, see sqlite implementation for compare. @@ -224,7 +223,6 @@ constexpr uint32_t FLATBUFFER_MAX_CACHE_SIZE = 102400; // 100 KBytes void FlatBufferCacheFree(std::vector *inCache) { delete inCache; - inCache = nullptr; } } diff --git a/frameworks/libs/distributeddb/storage/src/storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/storage_engine.cpp index 5e40a9d1187..7245aef5c23 100644 --- a/frameworks/libs/distributeddb/storage/src/storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/storage_engine.cpp @@ -245,12 +245,10 @@ void StorageEngine::Recycle(StorageExecutor *&handle, bool isExternal) if (!isEnhance_) { LOGD("Recycle executor[%d] for id[%.6s]", handle->GetWritable(), hashIdentifier_.c_str()); } - std::list &writeUsingList = isExternal ? externalWriteUsingList_ : writeUsingList_; - std::list &writeIdleList = isExternal ? externalWriteIdleList_ : writeIdleList_; - std::list &readUsingList = isExternal ? externalReadUsingList_ : readUsingList_; - std::list &readIdleList = isExternal ? externalReadIdleList_ : readIdleList_; if (handle->GetWritable()) { std::unique_lock lock(writeMutex_); + std::list &writeUsingList = isExternal ? externalWriteUsingList_ : writeUsingList_; + std::list &writeIdleList = isExternal ? externalWriteIdleList_ : writeIdleList_; auto iter = std::find(writeUsingList.begin(), writeUsingList.end(), handle); if (iter != writeUsingList.end()) { writeUsingList.remove(handle); @@ -266,6 +264,8 @@ void StorageEngine::Recycle(StorageExecutor *&handle, bool isExternal) } } else { std::unique_lock lock(readMutex_); + std::list &readUsingList = isExternal ? externalReadUsingList_ : readUsingList_; + std::list &readIdleList = isExternal ? externalReadIdleList_ : readIdleList_; auto iter = std::find(readUsingList.begin(), readUsingList.end(), handle); if (iter != readUsingList.end()) { readUsingList.remove(handle); @@ -416,11 +416,11 @@ void StorageEngine::AddStorageExecutor(StorageExecutor *handle, bool isExternal) return; } - std::list &writeIdleList = isExternal ? externalWriteIdleList_ : writeIdleList_; - std::list &readIdleList = isExternal ? externalReadIdleList_ : readIdleList_; if (handle->GetWritable()) { + std::list &writeIdleList = isExternal ? externalWriteIdleList_ : writeIdleList_; writeIdleList.push_back(handle); } else { + std::list &readIdleList = isExternal ? externalReadIdleList_ : readIdleList_; readIdleList.push_back(handle); } } diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp index 36318036f1f..551c5606b48 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp @@ -771,13 +771,9 @@ std::vector CloudDBProxy::GetNotEmptyAssetRecords(std::vector CloudDBProxy::GetNotEmptyAssetRecords(std::vector &originalRecords, - const std::vector indexes, std::vector &newRecords) + const std::vector &indexes, std::vector &newRecords) { int i = 0; for (const auto index : indexes) { diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h index f706c90e6b3..018c987343e 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h @@ -187,11 +187,11 @@ protected: std::vector &necessaryRecords, const InnerBatchOpType operationType); // save record with assets in nonEmptyRecords, return the indexes of these records in the original vector - std::vector GetNotEmptyAssetRecords(std::vector &originalRecords, + static std::vector GetNotEmptyAssetRecords(std::vector &originalRecords, std::vector &nonEmptyRecords); // copy newRecords's assets and status back to originalRecords, based on indexes - void CopyAssetsBack(std::vector &originalRecords, const std::vector indexes, + static void CopyAssetsBack(std::vector &originalRecords, const std::vector &indexes, std::vector &newRecords); mutable std::shared_mutex cloudMutex_; diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h index c37540fdd03..eeb07ddc29e 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h @@ -459,7 +459,7 @@ protected: using DownloadAssetsRecords = std::vector; using DownloadAssetDetail = std::tuple; DownloadAssetDetail GetDownloadRecords(const DownloadList &downloadList, const std::set &dupHashKeySet, - bool isSharedTable, InnerProcessInfo &info); + bool isSharedTable, const InnerProcessInfo &info); int BatchDownloadAndCommitRes(const DownloadList &downloadList, const std::set &dupHashKeySet, InnerProcessInfo &info, ChangedData &changedAssets, diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend.cpp index cc3ef7ffb86..9af87b83e03 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend.cpp +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend.cpp @@ -1438,7 +1438,7 @@ void CloudSyncer::FillDownloadItem(const std::set &dupHashKeySet, const Dow } CloudSyncer::DownloadAssetDetail CloudSyncer::GetDownloadRecords(const DownloadList &downloadList, - const std::set &dupHashKeySet, bool isSharedTable, InnerProcessInfo &info) + const std::set &dupHashKeySet, bool isSharedTable, const InnerProcessInfo &info) { DownloadItemRecords downloadRecord; RemoveAssetsRecords removeAssets; diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_extend.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_extend.cpp index cbfeb722179..f5fb5dbcb25 100644 --- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_extend.cpp +++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_extend.cpp @@ -103,7 +103,6 @@ int SingleVerDataSync::SendControlPacket(ControlRequestPacket *packet, SingleVer int errCode = message->SetExternalObject(packet); if (errCode != E_OK) { delete packet; - packet = nullptr; delete message; message = nullptr; LOGE("[DataSync][SendControlPacket] set external object failed errCode=%d", errCode); -- Gitee