From b66f82a888c3f8dced862bf3f69d9cda99268aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=A0=8B?= Date: Sat, 28 Dec 2024 14:04:57 +0800 Subject: [PATCH 1/7] =?UTF-8?q?Signed-off-by:=20=E7=8E=8B=E4=BD=B3?= =?UTF-8?q?=E6=A0=8B=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add --- .../flow_update/update_bin/component_processor.cpp | 12 ++++++++++++ services/package/pkg_verify/pkg_verify_util.cpp | 1 + .../script/script_interpreter/script_interpreter.cpp | 1 + .../script/script_manager/script_managerImpl.cpp | 1 + services/updater_binary/update_processor.cpp | 1 + 5 files changed, 16 insertions(+) diff --git a/services/flow_update/update_bin/component_processor.cpp b/services/flow_update/update_bin/component_processor.cpp index 18f45b9a..0c1a0b08 100644 --- a/services/flow_update/update_bin/component_processor.cpp +++ b/services/flow_update/update_bin/component_processor.cpp @@ -17,6 +17,7 @@ #include #include "applypatch/data_writer.h" #include "applypatch/partition_record.h" +#include "dump.h" #include "log.h" #include "parameter.h" #ifdef UPDATER_USE_PTABLE @@ -141,10 +142,12 @@ int32_t BoardIdCheckProcessor::DoProcess(Uscript::UScriptEnv &env) int32_t RawImgProcessor::PreProcess(Uscript::UScriptEnv &env) { + UPDATER_INIT_RECORD; std::string partitionName = name_; LOG(INFO) << "RawImgProcessor::PreProcess " << partitionName; if (env.GetPkgManager() == nullptr) { LOG(ERROR) << "Error to get pkg manager"; + UPDATER_LAST_WORD(partitionName, "Error to get pkg manager"); return USCRIPT_ERROR_EXECUTE; } @@ -154,16 +157,20 @@ int32_t RawImgProcessor::PreProcess(Uscript::UScriptEnv &env) if (GetWritePathAndOffset(partitionName, writePath, offset, partitionSize) != USCRIPT_SUCCESS) { LOG(ERROR) << "Get partition:%s WritePathAndOffset fail \'" << partitionName.substr(1, partitionName.size()) << "\'."; + UPDATER_LAST_WORD("Get partition:%s WritePathAndOffset fail \'" << + partitionName.substr(1, partitionName.size()) << "\'."); return USCRIPT_ERROR_EXECUTE; } const FileInfo *info = env.GetPkgManager()->GetFileInfo(partitionName); if (info == nullptr) { LOG(ERROR) << "Error to get file info"; + UPDATER_LAST_WORD("Error to get file info"); return USCRIPT_ERROR_EXECUTE; } #ifdef UPDATER_USE_PTABLE if (partitionSize < info->unpackedSize) { LOG(ERROR) << "partition size: " << partitionSize << " is short than image size: " << totalSize_; + UPDATER_LAST_WORD(partitionName, "partition size: " << partitionSize << " is short than image size: " << totalSize_); return USCRIPT_ERROR_EXECUTE; } #endif @@ -172,6 +179,7 @@ int32_t RawImgProcessor::PreProcess(Uscript::UScriptEnv &env) static_cast(&env), offset); if (writer_ == nullptr) { LOG(ERROR) << "Error to create writer"; + UPDATER_LAST_WORD(partitionName, "Error to create writer"); return USCRIPT_ERROR_EXECUTE; } #ifdef UPDATER_UT @@ -185,11 +193,13 @@ int32_t RawImgProcessor::PreProcess(Uscript::UScriptEnv &env) int32_t RawImgProcessor::DoProcess(Uscript::UScriptEnv &env) { + UPDATER_INIT_RECORD; std::string partitionName = name_; // Extract partition information const FileInfo *info = env.GetPkgManager()->GetFileInfo(partitionName); if (info == nullptr) { LOG(ERROR) << "Error to get file info"; + UPDATER_LAST_WORD(partitionName, "Error to get file info"); return USCRIPT_ERROR_EXECUTE; } @@ -202,6 +212,7 @@ int32_t RawImgProcessor::DoProcess(Uscript::UScriptEnv &env) int ret = env.GetPkgManager()->CreatePkgStream(outStream, partitionName, processor, writer_.get()); if (ret != USCRIPT_SUCCESS || outStream == nullptr) { LOG(ERROR) << "Error to create output stream"; + UPDATER_LAST_WORD(partitionName, "Error to create output stream"); return USCRIPT_ERROR_EXECUTE; } @@ -209,6 +220,7 @@ int32_t RawImgProcessor::DoProcess(Uscript::UScriptEnv &env) if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to extract file"; env.GetPkgManager()->ClosePkgStream(outStream); + UPDATER_LAST_WORD(partitionName, "Error to extract file"); return USCRIPT_ERROR_EXECUTE; } env.GetPkgManager()->ClosePkgStream(outStream); diff --git a/services/package/pkg_verify/pkg_verify_util.cpp b/services/package/pkg_verify/pkg_verify_util.cpp index 596c7bc4..3dc251d9 100644 --- a/services/package/pkg_verify/pkg_verify_util.cpp +++ b/services/package/pkg_verify/pkg_verify_util.cpp @@ -135,6 +135,7 @@ int32_t PkgVerifyUtil::VerifyPackageSign(const PkgStreamPtr pkgStream, const std int32_t PkgVerifyUtil::GetSignature(const PkgStreamPtr pkgStream, size_t &signatureSize, std::vector &signature, uint16_t &commentTotalLenAll) const { + UPDATER_INIT_RECORD' size_t signatureStart = 0; int32_t ret = ParsePackage(pkgStream, signatureStart, signatureSize, commentTotalLenAll); if (ret != PKG_SUCCESS || signatureSize < PKG_FOOTER_SIZE) { diff --git a/services/script/script_interpreter/script_interpreter.cpp b/services/script/script_interpreter/script_interpreter.cpp index edb3a2e3..9ca1e87a 100644 --- a/services/script/script_interpreter/script_interpreter.cpp +++ b/services/script/script_interpreter/script_interpreter.cpp @@ -28,6 +28,7 @@ static int32_t g_instanceId = 0; int32_t ScriptInterpreter::ExecuteScript(ScriptManagerImpl *manager, Hpackage::PkgManager::StreamPtr pkgStream) { + UPDATER_INIT_RECORD; if (pkgStream == nullptr) { USCRIPT_LOGE("Param error"); UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); diff --git a/services/script/script_manager/script_managerImpl.cpp b/services/script/script_manager/script_managerImpl.cpp index 4ec8f40b..034322f0 100644 --- a/services/script/script_manager/script_managerImpl.cpp +++ b/services/script/script_manager/script_managerImpl.cpp @@ -205,6 +205,7 @@ int32_t ScriptManagerImpl::ExtractAndExecuteScript(PkgManager::PkgManagerPtr man int32_t ScriptManagerImpl::ExecuteScript(int32_t priority) { + UPDATER_INIT_RECORD; if (priority >= MAX_PRIORITY || priority < 0) { USCRIPT_LOGE("ExecuteScript priority not support %d", priority); UPDATER_LAST_WORD(USCRIPT_INVALID_PRIORITY, priority); diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 9b7ee341..1551a906 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -384,6 +384,7 @@ int UScriptInstructionUpdateFromBin::UnCompressDataProducer(const PkgBuffer &buf int ExecUpdate(PkgManager::PkgManagerPtr pkgManager, int retry, const std::string &pkgPath, PostMessageFunction postMessage) { + UPDATER_INIT_RECORD; Hpackage::HashDataVerifier scriptVerifier {pkgManager}; if (!scriptVerifier.LoadHashDataAndPkcs7(pkgPath)) { LOG(ERROR) << "Fail to load hash data"; -- Gitee From 43870e5ad7db428c14c30cdc39e7cc37eabcf6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=A0=8B?= Date: Sat, 28 Dec 2024 15:41:59 +0800 Subject: [PATCH 2/7] =?UTF-8?q?Signed-off-by:=20=E7=8E=8B=E4=BD=B3?= =?UTF-8?q?=E6=A0=8B=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add --- services/package/pkg_manager/pkg_managerImpl.cpp | 8 ++++++++ services/package/pkg_package/pkg_gzipfile.cpp | 1 + services/package/pkg_package/pkg_pkgfile.cpp | 1 + services/package/pkg_package/pkg_upgradefile.cpp | 5 +++++ services/package/pkg_package/pkg_zipfile.cpp | 2 ++ services/package/pkg_verify/hash_data_verifier.cpp | 2 ++ services/package/pkg_verify/zip_pkg_parse.cpp | 2 ++ services/script/script_instruction/script_loadscript.cpp | 1 + services/script/script_instruction/script_registercmd.cpp | 1 + services/updater_binary/update_image_block.cpp | 4 ++++ services/updater_binary/update_image_patch.cpp | 1 + services/updater_binary/update_partitions.cpp | 1 + services/updater_binary/update_processor.cpp | 2 ++ 13 files changed, 31 insertions(+) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index b7004c96..52542a92 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -278,6 +278,7 @@ int32_t PkgManagerImpl::ParsePackage(StreamPtr stream, std::vector int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::string &keyPath, std::vector &fileIds) { + UPDATER_INIT_RECORD; if (access(packagePath.c_str(), 0) != 0) { UPDATER_LAST_WORD(PKG_INVALID_FILE); return PKG_INVALID_FILE; @@ -382,6 +383,7 @@ int32_t PkgManagerImpl::ExtraAndLoadPackage(const std::string &path, const std:: int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, std::vector &fileIds, PkgFile::PkgType type) { + UPDATER_INIT_RECORD; PkgStreamPtr stream = nullptr; int32_t ret = CreatePkgStream(stream, packagePath, 0, PkgStream::PKgStreamType_FileMap); if (ret != PKG_SUCCESS) { @@ -395,6 +397,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, std::vector< int32_t PkgManagerImpl::LoadPackageWithStreamForApp(AppPkgInfo &info, std::vector &fileIds, StreamPtr stream) { + UPDATER_INIT_RECORD; int32_t ret = SetSignVerifyKeyName(info.keyPath); if (ret != PKG_SUCCESS) { PKG_LOGE("Invalid keyname"); @@ -446,6 +449,7 @@ int32_t PkgManagerImpl::LoadPackageWithStream(const std::string &packagePath, co int32_t PkgManagerImpl::LoadPackageWithStream(const std::string &packagePath, std::vector &fileIds, PkgFile::PkgType type, PkgStreamPtr stream) { + UPDATER_INIT_RECORD; int32_t ret = PKG_SUCCESS; PkgFilePtr pkgFile = CreatePackage(stream, type, nullptr); if (pkgFile == nullptr) { @@ -471,6 +475,7 @@ int32_t PkgManagerImpl::LoadPackageWithStream(const std::string &packagePath, int32_t PkgManagerImpl::ExtractFile(const std::string &path, PkgManager::StreamPtr output) { + UPDATER_INIT_RECORD; if (output == nullptr) { PKG_LOGE("Invalid stream"); UPDATER_LAST_WORD(PKG_INVALID_STREAM); @@ -568,6 +573,7 @@ int32_t PkgManagerImpl::CreatePkgStream(StreamPtr &stream, const std::string &fi int32_t PkgManagerImpl::DoCreatePkgStream(PkgStreamPtr &stream, const std::string &fileName, int32_t type) { + UPDATER_INIT_RECORD; static char const *modeFlags[] = { "rb", "wb+" }; char realPath[PATH_MAX + 1] = {}; #ifdef _WIN32 @@ -1005,6 +1011,7 @@ void PkgManagerImpl::PostDecodeProgress(int type, size_t writeDataLen, const voi int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) { + UPDATER_INIT_RECORD; PkgStreamPtr pkgStream = nullptr; int32_t ret = CreatePkgStream(pkgStream, packagePath, 0, PkgStream::PkgStreamType_Read); if (ret != PKG_SUCCESS) { @@ -1081,6 +1088,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &packagePath) { + UPDATER_INIT_RECORD; PkgStreamPtr pkgStream = nullptr; int32_t ret = CreatePkgStream(pkgStream, packagePath, 0, PkgStream::PkgStreamType_Read); if (ret != PKG_SUCCESS) { diff --git a/services/package/pkg_package/pkg_gzipfile.cpp b/services/package/pkg_package/pkg_gzipfile.cpp index 777b2d8b..03968c42 100644 --- a/services/package/pkg_package/pkg_gzipfile.cpp +++ b/services/package/pkg_package/pkg_gzipfile.cpp @@ -354,6 +354,7 @@ int32_t GZipPkgFile::SavePackage(size_t &offset) int32_t GZipPkgFile::LoadPackage(std::vector &fileNames, VerifyFunction verifier) { + UPDATER_INIT_RECORD; UNUSED(verifier); if (!CheckState({ PKG_FILE_STATE_IDLE }, PKG_FILE_STATE_WORKING)) { PKG_LOGE("error state curr %d ", state_); diff --git a/services/package/pkg_package/pkg_pkgfile.cpp b/services/package/pkg_package/pkg_pkgfile.cpp index d912daad..7e9dbd94 100644 --- a/services/package/pkg_package/pkg_pkgfile.cpp +++ b/services/package/pkg_package/pkg_pkgfile.cpp @@ -68,6 +68,7 @@ PkgEntryPtr PkgFileImpl::AddPkgEntry(const std::string &fileName) int32_t PkgFileImpl::ExtractFile(const PkgEntryPtr node, PkgStreamPtr output) { + UPDATER_INIT_RECORD; PKG_LOGI("ExtractFile %s", output->GetFileName().c_str()); if (!CheckState({PKG_FILE_STATE_WORKING}, PKG_FILE_STATE_WORKING)) { PKG_LOGE("error state curr %d ", state_); diff --git a/services/package/pkg_package/pkg_upgradefile.cpp b/services/package/pkg_package/pkg_upgradefile.cpp index 06999dcf..2094417d 100644 --- a/services/package/pkg_package/pkg_upgradefile.cpp +++ b/services/package/pkg_package/pkg_upgradefile.cpp @@ -264,6 +264,7 @@ int32_t UpgradePkgFile::SavePackage(size_t &signOffset) int32_t UpgradePkgFile::ReadSignData(std::vector &signData, size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm) { + UPDATER_INIT_RECORD; size_t readBytes = 0; size_t signLen = parsedLen; PkgBuffer buffer(HASH_TLV_SIZE); @@ -306,6 +307,7 @@ int32_t UpgradePkgFile::ReadSignData(std::vector &signData, int32_t UpgradePkgFile::ReadImgHashTLV(std::vector &imgHashBuf, size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm, uint32_t needType) { + UPDATER_INIT_RECORD; size_t readBytes = 0; PkgBuffer buffer(HASH_TLV_SIZE); int32_t ret = pkgStream_->Read(buffer, parsedLen, buffer.length, readBytes); @@ -340,6 +342,7 @@ int32_t UpgradePkgFile::ReadImgHashTLV(std::vector &imgHashBuf, size_t int32_t UpgradePkgFile::ReadImgHashData(size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm) { + UPDATER_INIT_RECORD; #ifndef DIFF_PATCH_SDK if ((!Updater::Utils::CheckUpdateMode(Updater::SDCARD_MODE) && !Updater::Utils::CheckUpdateMode(Updater::USB_MODE) && @@ -390,6 +393,7 @@ int32_t UpgradePkgFile::ReadImgHashData(size_t &parsedLen, DigestAlgorithm::Dige int32_t UpgradePkgFile::ReadPackageInfo(std::vector &signData, size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm) { + UPDATER_INIT_RECORD; PkgBuffer buffer(GetUpgradeSignatureLen() + UPGRADE_RESERVE_LEN); size_t readBytes = 0; int32_t ret = pkgStream_->Read(buffer, parsedLen, buffer.length, readBytes); @@ -434,6 +438,7 @@ int32_t UpgradePkgFile::ReadPackageInfo(std::vector &signData, size_t & int32_t UpgradePkgFile::LoadPackage(std::vector &fileNames, VerifyFunction verifier) { + UPDATER_INIT_RECORD; if (verifier == nullptr) { PKG_LOGE("Check verifier nullptr"); UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE); diff --git a/services/package/pkg_package/pkg_zipfile.cpp b/services/package/pkg_package/pkg_zipfile.cpp index 59f7ab41..9ac2c3a0 100644 --- a/services/package/pkg_package/pkg_zipfile.cpp +++ b/services/package/pkg_package/pkg_zipfile.cpp @@ -120,6 +120,7 @@ int32_t ZipPkgFile::SavePackage(size_t &signOffset) int32_t ZipPkgFile::LoadPackage(std::vector &fileNames, PkgBuffer &buffer, uint32_t endDirLen, size_t endDirPos, size_t &readLen) { + UPDATER_INIT_RECORD; size_t fileLen = pkgStream_->GetFileLength(); EndCentralDir endDir; endDir.signature = ReadLE32(buffer.buffer + offsetof(EndCentralDir, signature)); @@ -184,6 +185,7 @@ int32_t ZipPkgFile::GetFileLength(size_t &fileLen) int32_t ZipPkgFile::LoadPackage(std::vector& fileNames, VerifyFunction verifier) { + UPDATER_INIT_RECORD; UNUSED(verifier); PKG_LOGI("LoadPackage %s :%zu", pkgStream_->GetFileName().c_str(), pkgStream_->GetFileLength()); diff --git a/services/package/pkg_verify/hash_data_verifier.cpp b/services/package/pkg_verify/hash_data_verifier.cpp index 895d57a9..eb1ad39c 100644 --- a/services/package/pkg_verify/hash_data_verifier.cpp +++ b/services/package/pkg_verify/hash_data_verifier.cpp @@ -113,6 +113,7 @@ bool HashDataVerifier::LoadHashDataFromPackage(void) bool HashDataVerifier::LoadPkcs7FromPackage(const std::string &pkgPath) { + UPDATER_INIT_RECORD; PkgManager::StreamPtr pkgStream = nullptr; int32_t ret = manager_->CreatePkgStream(pkgStream, pkgPath, 0, PkgStream::PkgStreamType_Read); if (ret != PKG_SUCCESS) { @@ -139,6 +140,7 @@ bool HashDataVerifier::LoadPkcs7FromPackage(const std::string &pkgPath) bool HashDataVerifier::VerifyHashData(const std::string &preName, const std::string &fileName, PkgManager::StreamPtr stream) const { + UPDATER_INIT_RECORD; if (!isNeedVerify_) { return true; } diff --git a/services/package/pkg_verify/zip_pkg_parse.cpp b/services/package/pkg_verify/zip_pkg_parse.cpp index 947cd26c..07e9ca65 100644 --- a/services/package/pkg_verify/zip_pkg_parse.cpp +++ b/services/package/pkg_verify/zip_pkg_parse.cpp @@ -51,6 +51,7 @@ const uint8_t ZIP_EOCD_SIGNATURE_BIG_ENDIAN[4] = {0x50, 0x4b, 0x05, 0x06}; int32_t ZipPkgParse::DoParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSignComment, size_t &readLen, const uint16_t &signCommentAppendLen, uint16_t &signCommentTotalLen) const { + UPDATER_INIT_RECORD; size_t fileLen = pkgStream->GetFileLength(); size_t eocdTotalLen = ZIP_EOCD_FIXED_PART_LEN + signCommentTotalLen; if (fileLen <= eocdTotalLen) { @@ -88,6 +89,7 @@ int32_t ZipPkgParse::DoParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSi int32_t ZipPkgParse::ParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSignComment) const { + UPDATER_INIT_RECORD; if (pkgStream == nullptr) { UPDATER_LAST_WORD(PKG_INVALID_PARAM); return PKG_INVALID_PARAM; diff --git a/services/script/script_instruction/script_loadscript.cpp b/services/script/script_instruction/script_loadscript.cpp index ca4cd7ee..20709ade 100644 --- a/services/script/script_instruction/script_loadscript.cpp +++ b/services/script/script_instruction/script_loadscript.cpp @@ -24,6 +24,7 @@ using namespace Uscript; namespace BasicInstruction { int32_t ScriptLoadScript::Execute(UScriptEnv &env, UScriptContext &context) { + UPDATER_INIT_RECORD; ScriptInstructionHelper* helper = ScriptInstructionHelper::GetBasicInstructionHelper(); if (helper == nullptr) { USCRIPT_LOGE("Failed to get instruction helper"); diff --git a/services/script/script_instruction/script_registercmd.cpp b/services/script/script_instruction/script_registercmd.cpp index 66c133d1..52245570 100644 --- a/services/script/script_instruction/script_registercmd.cpp +++ b/services/script/script_instruction/script_registercmd.cpp @@ -25,6 +25,7 @@ using namespace Uscript; namespace BasicInstruction { int32_t ScriptRegisterCmd::Execute(UScriptEnv &env, UScriptContext &context) { + UPDATER_INIT_RECORD; ScriptInstructionHelper* helper = ScriptInstructionHelper::GetBasicInstructionHelper(); if (helper == nullptr) { USCRIPT_LOGE("Fail to get instruction helper"); diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 3f68572f..8dbec88d 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -435,6 +435,7 @@ bool UScriptInstructionBlockCheck::ExecReadBlockInfo(const std::string &devPath, int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { + UPDATER_INIT_RECORD; if (context.GetParamCount() != 1) { LOG(ERROR) << "Invalid param"; UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); @@ -602,6 +603,7 @@ void UScriptInstructionShaCheck::PrintAbnormalBlockHash(const std::string &devPa std::string UScriptInstructionShaCheck::CalculateBlockSha(const std::string &devPath, const std::string &blockPairs) { + UPDATER_INIT_RECORD; if (blockPairs.empty()) { LOG(ERROR) << "Failed to get blockPairs"; return ""; @@ -646,6 +648,7 @@ std::string UScriptInstructionShaCheck::CalculateBlockSha(const std::string &dev int32_t UScriptInstructionShaCheck::SetShaInfo(Uscript::UScriptContext &context, ShaInfo &shaInfo) { + UPDATER_INIT_RECORD; int32_t ret = context.GetParam(1, shaInfo.blockPairs); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Failed to get param blockPairs"; @@ -676,6 +679,7 @@ int32_t UScriptInstructionShaCheck::SetShaInfo(Uscript::UScriptContext &context, int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { + UPDATER_INIT_RECORD; int32_t paramCount = context.GetParamCount(); if (paramCount != SHA_CHECK_PARAMS && paramCount != SHA_CHECK_TARGET_PARAMS) { LOG(ERROR) << "Invalid param"; diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index 55654a50..d7252770 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -173,6 +173,7 @@ std::string USInstrImagePatch::GetSourceFile(const ImagePatchPara ¶) int32_t USInstrImagePatch::ExecuteImagePatch(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { + UPDATER_INIT_RECORD; ImagePatchPara para {}; int32_t ret = GetParam(context, para); if (ret != USCRIPT_SUCCESS) { diff --git a/services/updater_binary/update_partitions.cpp b/services/updater_binary/update_partitions.cpp index 0eff03f3..2b6241dc 100644 --- a/services/updater_binary/update_partitions.cpp +++ b/services/updater_binary/update_partitions.cpp @@ -198,6 +198,7 @@ int UpdatePartitions::SetNewPartition(const std::string &filePath, const FileInf int32_t UpdatePartitions::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { + UPDATER_INIT_RECORD; LOG(INFO) << "enter UpdatePartitions::Execute "; if (context.GetParamCount() != 1) { LOG(ERROR) << "Invalid UpdatePartitions::Execute param"; diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 1551a906..233f1e7d 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -186,6 +186,7 @@ bool UScriptInstructionRawImageWrite::WriteRawImage(const std::string &partition int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { + UPDATER_INIT_RECORD; std::string partitionName; int32_t ret = context.GetParam(0, partitionName); if (ret != USCRIPT_SUCCESS) { @@ -241,6 +242,7 @@ int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscri int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { + UPDATER_INIT_RECORD; std::string pkgFileName; int32_t ret = context.GetParam(0, pkgFileName); if (ret != USCRIPT_SUCCESS) { -- Gitee From 64a2b82c568c78423d881daa18e5d11bf5453653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=A0=8B?= Date: Mon, 30 Dec 2024 22:41:21 +0800 Subject: [PATCH 3/7] =?UTF-8?q?Signed-off-by:=20=E7=8E=8B=E4=BD=B3?= =?UTF-8?q?=E6=A0=8B=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix --- services/fs_manager/mount.cpp | 6 +- .../package/pkg_manager/pkg_managerImpl.cpp | 42 ++++++------ services/package/pkg_manager/pkg_stream.cpp | 12 ++-- services/package/pkg_package/pkg_gzipfile.cpp | 16 ++--- services/package/pkg_package/pkg_pkgfile.cpp | 2 +- .../package/pkg_package/pkg_upgradefile.cpp | 51 +++++++------- services/package/pkg_package/pkg_zipfile.cpp | 18 ++--- services/package/pkg_verify/cert_verify.cpp | 1 + .../package/pkg_verify/hash_data_verifier.cpp | 22 +++--- services/package/pkg_verify/openssl_util.cpp | 18 ++--- .../package/pkg_verify/pkcs7_signed_data.cpp | 68 ++++++++++--------- .../package/pkg_verify/pkg_verify_util.cpp | 25 ++++--- services/package/pkg_verify/zip_pkg_parse.cpp | 22 +++--- .../script_instructionhelper.cpp | 14 ++-- .../script_instruction/script_loadscript.cpp | 8 +-- .../script_instruction/script_registercmd.cpp | 8 +-- .../script_interpreter/script_interpreter.cpp | 6 +- .../script_manager/script_managerImpl.cpp | 17 ++--- services/updater.cpp | 53 ++++++++------- .../updater_binary/update_image_block.cpp | 26 +++---- .../updater_binary/update_image_patch.cpp | 12 ++-- services/updater_binary/update_partitions.cpp | 6 +- services/updater_binary/update_processor.cpp | 42 ++++++------ services/updater_main.cpp | 38 ++++++----- 24 files changed, 278 insertions(+), 255 deletions(-) diff --git a/services/fs_manager/mount.cpp b/services/fs_manager/mount.cpp index 4b84c1d9..e73b7a02 100644 --- a/services/fs_manager/mount.cpp +++ b/services/fs_manager/mount.cpp @@ -316,7 +316,7 @@ int SetupPartitions(bool isMountData) if (g_fstab == NULL || g_fstab->head == NULL) { LOG(ERROR) << "Fstab is invalid"; - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "Fstab is invalid"); return -1; } for (const FstabItem *item = g_fstab->head; item != nullptr; item = item->next) { @@ -331,7 +331,7 @@ int SetupPartitions(bool isMountData) // factory wireless upgrade use /internaldata to mount userdata if (GetMountStatusForMountPoint(INTERNAL_DATA_PATH) != MOUNT_MOUNTED && MountForPath(mountPoint) != 0) { LOG(ERROR) << "Expected partition " << mountPoint << " is not mounted."; - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "Expected partition " + mountPoint + " is not mounted."); return -1; } Utils::SetParameter("updater.data.ready", "1"); @@ -340,7 +340,7 @@ int SetupPartitions(bool isMountData) } if (UmountForPath(mountPoint) != 0) { LOG(ERROR) << "Umount " << mountPoint << " failed"; - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "Umount " mountPoint + " failed"); return -1; } } diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 52542a92..fb595b76 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -280,11 +280,11 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::s { UPDATER_INIT_RECORD; if (access(packagePath.c_str(), 0) != 0) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "access pkgpath failed"); return PKG_INVALID_FILE; } if (SetSignVerifyKeyName(keyPath) != PKG_SUCCESS) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "SetSignVerifyKeyName failed"); return PKG_INVALID_FILE; } // Check if package already loaded @@ -299,7 +299,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::s int32_t ret = LoadPackage(packagePath, fileIds, pkgType); if (ret != PKG_SUCCESS) { ClearPkgFile(); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "LoadPackage failed"); PKG_LOGE("Parse %s fail ", packagePath.c_str()); return ret; } @@ -321,7 +321,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::s ret = ExtraAndLoadPackage(GetFilePath(packagePath), name, pkgType, fileIds); if (ret != PKG_SUCCESS) { ClearPkgFile(); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "ExtraAndLoadPackage failed"); PKG_LOGE("unpack %s fail in package %s ", name.c_str(), packagePath.c_str()); return ret; } @@ -388,7 +388,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, std::vector< int32_t ret = CreatePkgStream(stream, packagePath, 0, PkgStream::PKgStreamType_FileMap); if (ret != PKG_SUCCESS) { PKG_LOGE("Create input stream fail %s", packagePath.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "CreatePkgStream failed"); return ret; } return LoadPackageWithStream(packagePath, fileIds, type, stream); @@ -407,7 +407,7 @@ int32_t PkgManagerImpl::LoadPackageWithStreamForApp(AppPkgInfo &info, PkgFilePtr pkgFile = CreatePackage(stream, static_cast(info.type), nullptr); if (pkgFile == nullptr) { PKG_LOGE("Create package fail %s", info.packagePath.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Create package fail"); return PKG_INVALID_PARAM; } ret = pkgFile->ReadImgHashDataFile(info.pkgType); @@ -415,7 +415,7 @@ int32_t PkgManagerImpl::LoadPackageWithStreamForApp(AppPkgInfo &info, PKG_LOGE("Read img hash data fail %s", info.pkgType.c_str()); delete pkgFile; pkgFile = nullptr; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "ReadImgHashDataFile failed"); return ret; } ret = pkgFile->LoadPackage(fileIds, @@ -426,7 +426,7 @@ int32_t PkgManagerImpl::LoadPackageWithStreamForApp(AppPkgInfo &info, PKG_LOGE("Load package fail %s", info.packagePath.c_str()); delete pkgFile; pkgFile = nullptr; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Load package fail"); return ret; } pkgFiles_.push_back(pkgFile); @@ -455,7 +455,7 @@ int32_t PkgManagerImpl::LoadPackageWithStream(const std::string &packagePath, if (pkgFile == nullptr) { PKG_LOGE("Create package fail %s", packagePath.c_str()); ClosePkgStream(stream); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Create package fail"); return PKG_INVALID_PARAM; } @@ -466,7 +466,7 @@ int32_t PkgManagerImpl::LoadPackageWithStream(const std::string &packagePath, if (ret != PKG_SUCCESS) { PKG_LOGE("Load package fail %s", packagePath.c_str()); delete pkgFile; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Load package fail"); return ret; } pkgFiles_.push_back(pkgFile); @@ -478,7 +478,7 @@ int32_t PkgManagerImpl::ExtractFile(const std::string &path, PkgManager::StreamP UPDATER_INIT_RECORD; if (output == nullptr) { PKG_LOGE("Invalid stream"); - UPDATER_LAST_WORD(PKG_INVALID_STREAM); + UPDATER_LAST_WORD(PKG_INVALID_STREAM, "Invalid stream"); return PKG_INVALID_STREAM; } int32_t ret = PKG_INVALID_FILE; @@ -581,11 +581,11 @@ int32_t PkgManagerImpl::DoCreatePkgStream(PkgStreamPtr &stream, const std::strin #else if (type == PkgStream::PkgStreamType_Read && realpath(fileName.c_str(), realPath) == nullptr) { #endif - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "realPath failed"); return PKG_INVALID_FILE; } if (CheckFile(fileName, type) != PKG_SUCCESS) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "CheckFile failed"); PKG_LOGE("Fail to check file %s ", fileName.c_str()); return PKG_INVALID_FILE; } @@ -603,7 +603,7 @@ int32_t PkgManagerImpl::DoCreatePkgStream(PkgStreamPtr &stream, const std::strin file = fopen(fileName.c_str(), modeFlags[type]); } if (file == nullptr) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "Fail to open file " + fileName); PKG_LOGE("Fail to open file %s ", fileName.c_str()); return PKG_INVALID_FILE; } @@ -618,17 +618,17 @@ int32_t PkgManagerImpl::CreatePkgStream(PkgStreamPtr &stream, const std::string if (type == PkgStream::PkgStreamType_Write || type == PkgStream::PkgStreamType_Read) { int32_t ret = DoCreatePkgStream(stream, fileName, type); if (ret != PKG_SUCCESS) { - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "DoCreatePkgStream failed"); return ret; } } else if (type == PkgStream::PkgStreamType_MemoryMap || type == PkgStream::PKgStreamType_FileMap) { if ((size == 0) && (access(fileName.c_str(), 0) != 0)) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "can not access file " + fileName); return PKG_INVALID_FILE; } size_t fileSize = (size == 0) ? GetFileSize(fileName) : size; if (fileSize <= 0) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "Fail to check file size " + fileName); PKG_LOGE("Fail to check file size %s ", fileName.c_str()); return PKG_INVALID_FILE; } @@ -639,14 +639,14 @@ int32_t PkgManagerImpl::CreatePkgStream(PkgStreamPtr &stream, const std::string memoryMap = FileMap(fileName); } if (memoryMap == nullptr) { - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "Fail to map memory " + fileName); PKG_LOGE("Fail to map memory %s ", fileName.c_str()); return PKG_INVALID_FILE; } PkgBuffer buffer(memoryMap, fileSize); stream = new MemoryMapStream(this, fileName, buffer); } else { - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "type is not read or write " + fileName); return -1; } std::lock_guard lock(mapLock_); @@ -1093,7 +1093,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &packagePath) int32_t ret = CreatePkgStream(pkgStream, packagePath, 0, PkgStream::PkgStreamType_Read); if (ret != PKG_SUCCESS) { PKG_LOGE("CreatePackage fail %s", packagePath.c_str()); - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "CreatePackage fail"); return ret; } @@ -1101,7 +1101,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &packagePath) ret = verifyUtil.VerifyPackageSign(pkgStream, packagePath); if (ret != PKG_SUCCESS) { PKG_LOGE("Verify zpkcs7 signature failed."); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Verify zpkcs7 signature failed"); ClosePkgStream(pkgStream); return ret; } diff --git a/services/package/pkg_manager/pkg_stream.cpp b/services/package/pkg_manager/pkg_stream.cpp index c1727fe4..602821ea 100644 --- a/services/package/pkg_manager/pkg_stream.cpp +++ b/services/package/pkg_manager/pkg_stream.cpp @@ -29,7 +29,7 @@ #define ftello64 ftello #define fseeko64 fseek #endif - +using namespace Updater; namespace Hpackage { const std::string PkgStreamImpl::GetFileName() const { @@ -77,23 +77,23 @@ int32_t FileStream::Read(PkgBuffer &data, size_t start, size_t needRead, size_t Updater::UPDATER_INIT_RECORD; if (stream_ == nullptr) { PKG_LOGE("Invalid stream"); - UPDATER_LAST_WORD(PKG_INVALID_STREAM); + UPDATER_LAST_WORD(PKG_INVALID_STREAM, "Invalid stream"); return PKG_INVALID_STREAM; } if (data.length < needRead) { PKG_LOGE("insufficient buffer capacity"); - UPDATER_LAST_WORD(PKG_INVALID_STREAM); + UPDATER_LAST_WORD(PKG_INVALID_STREAM, "insufficient buffer capacity"); return PKG_INVALID_STREAM; } readLen = 0; if (fseeko64(stream_, start, SEEK_SET) != 0) { PKG_LOGE("read data fail"); - UPDATER_LAST_WORD(PKG_INVALID_STREAM); + UPDATER_LAST_WORD(PKG_INVALID_STREAM, "fseeko64 fail"); return PKG_INVALID_STREAM; } if (start > GetFileLength()) { PKG_LOGE("Invalid start"); - UPDATER_LAST_WORD(PKG_INVALID_STREAM); + UPDATER_LAST_WORD(PKG_INVALID_STREAM, "Invalid start"); return PKG_INVALID_STREAM; } if (data.buffer == nullptr) { @@ -103,7 +103,7 @@ int32_t FileStream::Read(PkgBuffer &data, size_t start, size_t needRead, size_t readLen = fread(data.buffer, 1, needRead, stream_); if (readLen == 0) { PKG_LOGE("read data fail"); - UPDATER_LAST_WORD(PKG_INVALID_STREAM); + UPDATER_LAST_WORD(PKG_INVALID_STREAM, "read data fail"); return PKG_INVALID_STREAM; } return PKG_SUCCESS; diff --git a/services/package/pkg_package/pkg_gzipfile.cpp b/services/package/pkg_package/pkg_gzipfile.cpp index 03968c42..03b29a18 100644 --- a/services/package/pkg_package/pkg_gzipfile.cpp +++ b/services/package/pkg_package/pkg_gzipfile.cpp @@ -262,7 +262,7 @@ int32_t GZipFileEntry::DecodeHeader(PkgBuffer &buffer, size_t headerOffset, size PkgStreamPtr inStream = pkgFile_->GetPkgStream(); if (inStream == nullptr || buffer.buffer == nullptr) { PKG_LOGE("outStream or inStream null for %s", fileInfo_.fileInfo.identity.c_str()); - UPDATER_LAST_WORD(PKG_INVALID_PARAM); + UPDATER_LAST_WORD(PKG_INVALID_PARAM, "outStream or inStream null for " + fileInfo_.fileInfo.identity); return PKG_INVALID_PARAM; } size_t offset = sizeof(GZipHeader); @@ -295,7 +295,7 @@ int32_t GZipFileEntry::DecodeHeader(PkgBuffer &buffer, size_t headerOffset, size int32_t ret = inStream->Read(buffer, blockOffset, buffer.length, readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("Fail to read file %s", inStream->GetFileName().c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to read file " + inStream->GetFileName()); return ret; } fileInfo_.fileInfo.unpackedSize = ReadLE32(buffer.buffer + sizeof(uint32_t)); @@ -354,11 +354,11 @@ int32_t GZipPkgFile::SavePackage(size_t &offset) int32_t GZipPkgFile::LoadPackage(std::vector &fileNames, VerifyFunction verifier) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; UNUSED(verifier); if (!CheckState({ PKG_FILE_STATE_IDLE }, PKG_FILE_STATE_WORKING)) { PKG_LOGE("error state curr %d ", state_); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "error state curr"); return PKG_INVALID_STATE; } PKG_LOGI("LoadPackage %s ", pkgStream_->GetFileName().c_str()); @@ -368,7 +368,7 @@ int32_t GZipPkgFile::LoadPackage(std::vector &fileNames, VerifyFunc int32_t ret = pkgStream_->Read(buffer, srcOffset, buffer.length, readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("Fail to read file %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to read file " + pkgStream_->GetFileName()); return ret; } @@ -376,20 +376,20 @@ int32_t GZipPkgFile::LoadPackage(std::vector &fileNames, VerifyFunc // Check magic number if (header->magic != GZIP_MAGIC) { PKG_LOGE("Invalid gzip file %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "Invalid gzip file " + pkgStream_->GetFileName()); return PKG_INVALID_FILE; } // Does not support encryption if ((header->flags & ENCRYPTED) != 0) { PKG_LOGE("Not support encrypted "); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "Not support encrypted"); return PKG_INVALID_FILE; } GZipFileEntry *entry = new GZipFileEntry(this, nodeId_++); if (entry == nullptr) { PKG_LOGE("Fail create gzip node for %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "Fail create gzip node for " + pkgStream_->GetFileName()); return PKG_LZ4_FINISH; } ret = entry->DecodeHeader(buffer, srcOffset, srcOffset, readLen); diff --git a/services/package/pkg_package/pkg_pkgfile.cpp b/services/package/pkg_package/pkg_pkgfile.cpp index 7e9dbd94..b4c2deb1 100644 --- a/services/package/pkg_package/pkg_pkgfile.cpp +++ b/services/package/pkg_package/pkg_pkgfile.cpp @@ -68,7 +68,7 @@ PkgEntryPtr PkgFileImpl::AddPkgEntry(const std::string &fileName) int32_t PkgFileImpl::ExtractFile(const PkgEntryPtr node, PkgStreamPtr output) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; PKG_LOGI("ExtractFile %s", output->GetFileName().c_str()); if (!CheckState({PKG_FILE_STATE_WORKING}, PKG_FILE_STATE_WORKING)) { PKG_LOGE("error state curr %d ", state_); diff --git a/services/package/pkg_package/pkg_upgradefile.cpp b/services/package/pkg_package/pkg_upgradefile.cpp index 2094417d..7e2899eb 100644 --- a/services/package/pkg_package/pkg_upgradefile.cpp +++ b/services/package/pkg_package/pkg_upgradefile.cpp @@ -264,7 +264,7 @@ int32_t UpgradePkgFile::SavePackage(size_t &signOffset) int32_t UpgradePkgFile::ReadSignData(std::vector &signData, size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; size_t readBytes = 0; size_t signLen = parsedLen; PkgBuffer buffer(HASH_TLV_SIZE); @@ -307,13 +307,13 @@ int32_t UpgradePkgFile::ReadSignData(std::vector &signData, int32_t UpgradePkgFile::ReadImgHashTLV(std::vector &imgHashBuf, size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm, uint32_t needType) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; size_t readBytes = 0; PkgBuffer buffer(HASH_TLV_SIZE); int32_t ret = pkgStream_->Read(buffer, parsedLen, buffer.length, readBytes); if (ret != PKG_SUCCESS) { PKG_LOGE("read image hash header fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read image hash header fail"); return ret; } @@ -331,7 +331,7 @@ int32_t UpgradePkgFile::ReadImgHashTLV(std::vector &imgHashBuf, size_t ret = pkgStream_->Read(dataBuf, parsedLen, dataBuf.length, readBytes); if (ret != PKG_SUCCESS) { PKG_LOGE("read hash data fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read hash data fail"); return ret; } parsedLen += dataBuf.length; @@ -342,7 +342,7 @@ int32_t UpgradePkgFile::ReadImgHashTLV(std::vector &imgHashBuf, size_t int32_t UpgradePkgFile::ReadImgHashData(size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; #ifndef DIFF_PATCH_SDK if ((!Updater::Utils::CheckUpdateMode(Updater::SDCARD_MODE) && !Updater::Utils::CheckUpdateMode(Updater::USB_MODE) && @@ -358,7 +358,7 @@ int32_t UpgradePkgFile::ReadImgHashData(size_t &parsedLen, DigestAlgorithm::Dige int32_t ret = ReadImgHashTLV(imgHashBuf, parsedLen, algorithm, TLV_TYPE_FOR_HASH_HEADER); if (ret != PKG_SUCCESS) { PKG_LOGE("read image hash info fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read image hash info fail"); return ret; } @@ -366,7 +366,7 @@ int32_t UpgradePkgFile::ReadImgHashData(size_t &parsedLen, DigestAlgorithm::Dige ret = ReadImgHashTLV(imgHashBuf, parsedLen, algorithm, TLV_TYPE_FOR_HASH_DATA); if (ret != PKG_SUCCESS) { PKG_LOGE("read image hash data fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read image hash data fail"); return ret; } @@ -393,13 +393,13 @@ int32_t UpgradePkgFile::ReadImgHashData(size_t &parsedLen, DigestAlgorithm::Dige int32_t UpgradePkgFile::ReadPackageInfo(std::vector &signData, size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr algorithm) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; PkgBuffer buffer(GetUpgradeSignatureLen() + UPGRADE_RESERVE_LEN); size_t readBytes = 0; int32_t ret = pkgStream_->Read(buffer, parsedLen, buffer.length, readBytes); if (ret != PKG_SUCCESS) { PKG_LOGE("read sign data fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read sign data fail"); return ret; } @@ -414,7 +414,7 @@ int32_t UpgradePkgFile::ReadPackageInfo(std::vector &signData, size_t & } if (ret != EOK) { PKG_LOGE("memcpy sign data fail"); - UPDATER_LAST_WORD(PKG_NONE_MEMORY); + UPDATER_LAST_WORD(PKG_NONE_MEMORY, "memcpy sign data fail"); return PKG_NONE_MEMORY; } @@ -428,7 +428,7 @@ int32_t UpgradePkgFile::ReadPackageInfo(std::vector &signData, size_t & ret = memset_s(buffer.buffer + UPGRADE_RESERVE_LEN, buffer.length, 0, GetUpgradeSignatureLen()); if (ret != EOK) { PKG_LOGE("memset buff fail"); - UPDATER_LAST_WORD(PKG_NONE_MEMORY); + UPDATER_LAST_WORD(PKG_NONE_MEMORY, "memset buff fail"); return PKG_NONE_MEMORY; } algorithm->Update(buffer, UPGRADE_RESERVE_LEN + GetUpgradeSignatureLen()); @@ -438,15 +438,15 @@ int32_t UpgradePkgFile::ReadPackageInfo(std::vector &signData, size_t & int32_t UpgradePkgFile::LoadPackage(std::vector &fileNames, VerifyFunction verifier) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; if (verifier == nullptr) { PKG_LOGE("Check verifier nullptr"); - UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE); + UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE, "Check verifier nullptr"); return PKG_INVALID_SIGNATURE; } if (!CheckState({PKG_FILE_STATE_IDLE}, PKG_FILE_STATE_WORKING)) { PKG_LOGE("error state curr %d ", state_); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "error state curr"); return PKG_INVALID_STATE; } PKG_LOGI("LoadPackage %s ", pkgStream_->GetFileName().c_str()); @@ -456,7 +456,7 @@ int32_t UpgradePkgFile::LoadPackage(std::vector &fileNames, VerifyF GetUpgradeSignatureLen() + UPGRADE_RESERVE_LEN; if (fileLen < buffSize) { PKG_LOGE("Invalid file %s fileLen:%zu ", pkgStream_->GetFileName().c_str(), fileLen); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "Invalid file " + pkgStream_->GetFileName().c_str(), fileLen); return PKG_INVALID_FILE; } @@ -466,14 +466,14 @@ int32_t UpgradePkgFile::LoadPackage(std::vector &fileNames, VerifyF int32_t ret = ReadUpgradePkgHeader(parsedLen, algorithm); if (ret != PKG_SUCCESS) { PKG_LOGE("Decode header fail %d", ret); - UPDATER_LAST_WORD(PKG_INVALID_STATE); + UPDATER_LAST_WORD(ret, "Decode header fail"); return ret; } ret = ReadComponents(parsedLen, algorithm, fileNames); if (ret != PKG_SUCCESS) { PKG_LOGE("Decode components fail %d", ret); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Decode components fail"); return ret; } @@ -550,7 +550,7 @@ int32_t UpgradePkgFile::Verify(size_t start, DigestAlgorithm::DigestAlgorithmPtr ret = pkgStream_->Read(buffer, offset, remainBytes, readBytes); if (ret != PKG_SUCCESS) { PKG_LOGE("Fail to read data "); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to read data "); return ret; } algorithm->Update(buffer, readBytes); @@ -562,7 +562,7 @@ int32_t UpgradePkgFile::Verify(size_t start, DigestAlgorithm::DigestAlgorithmPtr ret = verifier(&pkgInfo_.pkgInfo, digest.data, signData); if (ret != 0) { PKG_LOGE("Fail to verifier signature"); - UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE); + UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE, "Fail to verifier signature"); return PKG_INVALID_SIGNATURE; } return 0; @@ -643,7 +643,7 @@ int32_t UpgradePkgFile::ReadComponents(size_t &parsedLen, int32_t ret = pkgStream_->Read(buffer, parsedLen, buffer.length, info.readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("Read component fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Read component fail"); return ret; } PkgTlv tlv; @@ -664,7 +664,7 @@ int32_t UpgradePkgFile::ReadComponents(size_t &parsedLen, ret = pkgStream_->Read(compBuffer, parsedLen + info.srcOffset, compBuffer.length, info.readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("Fail to read data"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to read data"); return ret; } info.currLen = 0; @@ -672,7 +672,7 @@ int32_t UpgradePkgFile::ReadComponents(size_t &parsedLen, ret = SaveEntry(compBuffer, parsedLen, info, algorithm, fileNames); if (ret != PKG_SUCCESS) { PKG_LOGE("SaveEntry"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "SaveEntry"); return ret; } } @@ -704,6 +704,7 @@ void UpgradePkgFile::ParsePkgHeaderToTlv(const PkgBuffer &buffer, size_t &currLe int32_t UpgradePkgFile::ReadReserveData(size_t &parsedLen, DigestAlgorithm::DigestAlgorithmPtr &algorithm) { + Updater::UPDATER_INIT_RECORD; size_t readBytes = 0; PkgBuffer reserve_buf(UPGRADE_RESERVE_LEN); int32_t ret = pkgStream_->Read(reserve_buf, parsedLen, reserve_buf.length, readBytes); @@ -729,7 +730,7 @@ int32_t UpgradePkgFile::ReadUpgradePkgHeader(size_t &realLen, DigestAlgorithm::D int32_t ret = pkgStream_->Read(buffer, 0, buffer.length, readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("Fail to read header"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to read header"); return ret; } @@ -737,7 +738,7 @@ int32_t UpgradePkgFile::ReadUpgradePkgHeader(size_t &realLen, DigestAlgorithm::D algorithm = PkgAlgorithmFactory::GetDigestAlgorithm(pkgInfo_.pkgInfo.digestMethod); if (algorithm == nullptr) { PKG_LOGE("Invalid file %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(PKG_NOT_EXIST_ALGORITHM); + UPDATER_LAST_WORD(PKG_NOT_EXIST_ALGORITHM, "invalid file " + pkgStream_->GetFileName()); return PKG_NOT_EXIST_ALGORITHM; } algorithm->Init(); @@ -748,7 +749,7 @@ int32_t UpgradePkgFile::ReadUpgradePkgHeader(size_t &realLen, DigestAlgorithm::D ret = pkgStream_->Read(buffer, realLen, buffer.length, readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("Fail to read header"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to read TLV"); return ret; } currLen = 0; diff --git a/services/package/pkg_package/pkg_zipfile.cpp b/services/package/pkg_package/pkg_zipfile.cpp index 9ac2c3a0..b2325cc4 100644 --- a/services/package/pkg_package/pkg_zipfile.cpp +++ b/services/package/pkg_package/pkg_zipfile.cpp @@ -120,7 +120,7 @@ int32_t ZipPkgFile::SavePackage(size_t &signOffset) int32_t ZipPkgFile::LoadPackage(std::vector &fileNames, PkgBuffer &buffer, uint32_t endDirLen, size_t endDirPos, size_t &readLen) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; size_t fileLen = pkgStream_->GetFileLength(); EndCentralDir endDir; endDir.signature = ReadLE32(buffer.buffer + offsetof(EndCentralDir, signature)); @@ -185,7 +185,7 @@ int32_t ZipPkgFile::GetFileLength(size_t &fileLen) int32_t ZipPkgFile::LoadPackage(std::vector& fileNames, VerifyFunction verifier) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; UNUSED(verifier); PKG_LOGI("LoadPackage %s :%zu", pkgStream_->GetFileName().c_str(), pkgStream_->GetFileLength()); @@ -194,7 +194,7 @@ int32_t ZipPkgFile::LoadPackage(std::vector& fileNames, VerifyFunct int32_t ret = GetFileLength(fileLen); if (ret != PKG_SUCCESS) { PKG_LOGE("GetFileLength FAIL"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "GetFileLength FAIL"); return ret; } size_t buffSize = sizeof(EndCentralDir); @@ -211,7 +211,7 @@ int32_t ZipPkgFile::LoadPackage(std::vector& fileNames, VerifyFunct ret = pkgStream_->Read(buffer, endDirPos, sizeof(EndCentralDir), readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("read EOCD struct failed %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read EOCD struct failed " + pkgStream_->GetFileName()); return ret; } magic = ReadLE32(buffer.buffer); @@ -222,7 +222,7 @@ int32_t ZipPkgFile::LoadPackage(std::vector& fileNames, VerifyFunct signatureLen = pkgSignComment.signCommentTotalLen; if (ret != PKG_SUCCESS) { PKG_LOGE("Parse zip package signature failed"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Parse zip package signature failed"); return ret; } @@ -230,7 +230,7 @@ int32_t ZipPkgFile::LoadPackage(std::vector& fileNames, VerifyFunct ret = pkgStream_->Read(buffer, endDirPos, sizeof(EndCentralDir), readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("read EOCD struct failed %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read EOCD struct failed " + pkgStream_->GetFileName()); return ret; } } @@ -250,14 +250,14 @@ int32_t ZipPkgFile::ParseFileEntries(std::vector &fileNames, for (int32_t i = 0; i < endDir.totalEntries; i++) { if (fileLen <= currentPos) { PKG_LOGE("too small to be zip"); - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "too small to be zip"); return PKG_INVALID_FILE; } ZipFileEntry* entry = new ZipFileEntry(this, nodeId_++); if (entry == nullptr) { PKG_LOGE("Failed to create zip node for %s", pkgStream_->GetFileName().c_str()); - UPDATER_LAST_WORD(PKG_NONE_MEMORY); + UPDATER_LAST_WORD(PKG_NONE_MEMORY, "Failed to create zip node for " + pkgStream_->GetFileName()); return PKG_NONE_MEMORY; } @@ -267,7 +267,7 @@ int32_t ZipPkgFile::ParseFileEntries(std::vector &fileNames, if (ret != PKG_SUCCESS) { PKG_LOGE("DecodeHeader failed"); delete entry; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "DecodeHeader failed"); return ret; } diff --git a/services/package/pkg_verify/cert_verify.cpp b/services/package/pkg_verify/cert_verify.cpp index 9fc3b16c..6a954544 100644 --- a/services/package/pkg_verify/cert_verify.cpp +++ b/services/package/pkg_verify/cert_verify.cpp @@ -87,6 +87,7 @@ int32_t SingleCertHelper::CertChainCheck(STACK_OF(X509) * certStack, X509 *cert) int32_t SingleCertHelper::InitRootCert() { + UPDATER_INIT_RECORD; #ifndef DIFF_PATCH_SDK X509 *rootCert = GetX509CertFromPemFile(Utils::GetCertName()); if (rootCert == nullptr) { diff --git a/services/package/pkg_verify/hash_data_verifier.cpp b/services/package/pkg_verify/hash_data_verifier.cpp index eb1ad39c..1fa79361 100644 --- a/services/package/pkg_verify/hash_data_verifier.cpp +++ b/services/package/pkg_verify/hash_data_verifier.cpp @@ -55,12 +55,12 @@ bool HashDataVerifier::LoadHashDataAndPkcs7(const std::string &pkgPath) // load pkcs7 from package if (!LoadPkcs7FromPackage(pkgPath)) { PKG_LOGE("load pkcs7 from %s failed", pkgPath.c_str()); - UPDATER_LAST_WORD(PKG_INVALID_FILE, pkgPath); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "LoadPkcs7FromPackage failed " + pkgPath); return false; } if (!LoadHashDataFromPackage()) { PKG_LOGE("load pkcs7 from %s failed", pkgPath.c_str()); - UPDATER_LAST_WORD(PKG_INVALID_FILE, pkgPath); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "LoadHashDataFromPackage failed " + pkgPath); return false; } return true; @@ -83,7 +83,7 @@ bool HashDataVerifier::LoadHashDataFromPackage(void) auto info = manager_->GetFileInfo(UPDATER_HASH_SIGNED_DATA); if (info == nullptr || info->unpackedSize == 0) { PKG_LOGE("hash signed data not find in pkg manager"); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "hash signed data not find in pkg manager"); return false; } // 1 more byte bigger than unpacked size to ensure a ending '\0' in buffer @@ -91,21 +91,21 @@ bool HashDataVerifier::LoadHashDataFromPackage(void) int32_t ret = manager_->CreatePkgStream(outStream, "", buffer); if (ret != PKG_SUCCESS) { PKG_LOGE("create stream fail"); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "create stream fail"); return false; } ret = manager_->ExtractFile(UPDATER_HASH_SIGNED_DATA, outStream); if (ret != PKG_SUCCESS) { manager_->ClosePkgStream(outStream); PKG_LOGE("extract file failed"); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "extract file failed"); return false; } hsd_ = LoadHashSignedData(reinterpret_cast(buffer.data.data())); manager_->ClosePkgStream(outStream); if (hsd_ == nullptr) { PKG_LOGE("load hash signed data failed"); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "load hash signed data failed"); return false; } return true; @@ -113,13 +113,12 @@ bool HashDataVerifier::LoadHashDataFromPackage(void) bool HashDataVerifier::LoadPkcs7FromPackage(const std::string &pkgPath) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; PkgManager::StreamPtr pkgStream = nullptr; int32_t ret = manager_->CreatePkgStream(pkgStream, pkgPath, 0, PkgStream::PkgStreamType_Read); if (ret != PKG_SUCCESS) { PKG_LOGE("CreatePackage fail %s", pkgPath.c_str()); UPDATER_LAST_WORD(PKG_INVALID_FILE, pkgPath); - UPDATER_LAST_WORD(false); return false; } @@ -131,7 +130,7 @@ bool HashDataVerifier::LoadPkcs7FromPackage(const std::string &pkgPath) signatureSize, signature, commentTotalLenAll); manager_->ClosePkgStream(pkgStream); if (ret != PKG_SUCCESS) { - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "GetSignature failed"); return false; } return pkcs7_ != nullptr && pkcs7_->ParsePkcs7Data(signature.data(), signature.size()) == 0; @@ -140,14 +139,13 @@ bool HashDataVerifier::LoadPkcs7FromPackage(const std::string &pkgPath) bool HashDataVerifier::VerifyHashData(const std::string &preName, const std::string &fileName, PkgManager::StreamPtr stream) const { - UPDATER_INIT_RECORD; if (!isNeedVerify_) { return true; } Updater::UPDATER_INIT_RECORD; if (stream == nullptr) { PKG_LOGE("stream is null"); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "stream is null"); return false; } @@ -174,7 +172,7 @@ bool HashDataVerifier::VerifyHashData(const std::string &preName, // then using cert from pkcs7 to verify hash data if (pkcs7_ == nullptr || pkcs7_->Verify(hash, sig, false) != 0) { PKG_LOGE("verify hash signed data for %s failed", fileName.c_str()); - UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE, fileName); + UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE, "verify hash signed data failed for " + fileName); return false; } PKG_LOGI("verify hash signed data for %s successfully", fileName.c_str()); diff --git a/services/package/pkg_verify/openssl_util.cpp b/services/package/pkg_verify/openssl_util.cpp index a2ed3711..2554cc7d 100644 --- a/services/package/pkg_verify/openssl_util.cpp +++ b/services/package/pkg_verify/openssl_util.cpp @@ -156,27 +156,27 @@ int32_t VerifyDigestByPubKey(EVP_PKEY *pubKey, const int nid, const std::vector< Updater::UPDATER_INIT_RECORD; if (pubKey == nullptr) { PKG_LOGE("pubKey is empty"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "pubKey is empty"); return -1; } EVP_MD_CTX *mdCtx = EVP_MD_CTX_create(); if (mdCtx == nullptr) { PKG_LOGE("EVP_MD_CTX_create failed"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "EVP_MD_CTX_create failed"); return -1; } EVP_PKEY_CTX *pkeyCtx = nullptr; if (EVP_DigestVerifyInit(mdCtx, &pkeyCtx, EVP_get_digestbynid(nid), nullptr, pubKey) != 1) { PKG_LOGE("EVP init, error"); EVP_MD_CTX_destroy(mdCtx); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "EVP init, error"); return -1; } if (EVP_DigestVerifyUpdate(mdCtx, digestData.data(), digestData.size()) != 1) { PKG_LOGE("EVP update, error"); EVP_MD_CTX_destroy(mdCtx); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "EVP update, error"); return -1; } @@ -184,7 +184,7 @@ int32_t VerifyDigestByPubKey(EVP_PKEY *pubKey, const int nid, const std::vector< if (ret != 1) { PKG_LOGE("EVP final, error"); EVP_MD_CTX_destroy(mdCtx); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "EVP final, error"); return -1; } @@ -196,7 +196,7 @@ int32_t CalcSha256Digest(const PkgStreamPtr srcData, const size_t dataLen, std:: { Updater::UPDATER_INIT_RECORD; if (srcData == nullptr || dataLen == 0) { - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "input is invalid"); return -1; } if (result.size() != SHA256_DIGEST_LENGTH) { @@ -215,7 +215,7 @@ int32_t CalcSha256Digest(const PkgStreamPtr srcData, const size_t dataLen, std:: ret = srcData->Read(buffer, offset, blockLen, readLen); if (ret != 0) { PKG_LOGE("Fail read data"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(ret, "Fail read data"); return -1; } SHA256_Update(&ctx, buffer.buffer, readLen); @@ -226,7 +226,7 @@ int32_t CalcSha256Digest(const PkgStreamPtr srcData, const size_t dataLen, std:: ret = srcData->Read(buffer, offset, remainLen, readLen); if (ret != 0) { PKG_LOGE("Fail read data"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(ret, "Fail read remain data"); return -1; } SHA256_Update(&ctx, buffer.buffer, readLen); @@ -237,7 +237,7 @@ int32_t CalcSha256Digest(const PkgStreamPtr srcData, const size_t dataLen, std:: if (SHA256_Final(result.data(), &ctx) != 1) { PKG_LOGE("SHA256_Final(), error"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "SHA256_Final(), error"); return -1; } diff --git a/services/package/pkg_verify/pkcs7_signed_data.cpp b/services/package/pkg_verify/pkcs7_signed_data.cpp index e5843a0f..ba20d886 100644 --- a/services/package/pkg_verify/pkcs7_signed_data.cpp +++ b/services/package/pkg_verify/pkcs7_signed_data.cpp @@ -53,17 +53,18 @@ Pkcs7SignedData::~Pkcs7SignedData() int32_t Pkcs7SignedData::GetHashFromSignBlock(const uint8_t *srcData, const size_t dataLen, std::vector &hash) { + Updater::UPDATER_INIT_RECORD; int32_t ret = ParsePkcs7Data(srcData, dataLen); if (ret != 0) { PKG_LOGE("parse pkcs7 data fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "parse pkcs7 data fail"); return ret; } ret = Verify(); if (ret != 0) { PKG_LOGE("verify pkcs7 data fail"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "verify pkcs7 data fail"); return ret; } hash.assign(digest_.begin(), digest_.end()); @@ -73,13 +74,14 @@ int32_t Pkcs7SignedData::GetHashFromSignBlock(const uint8_t *srcData, const size int32_t Pkcs7SignedData::ParsePkcs7Data(const uint8_t *srcData, const size_t dataLen) { + Updater::UPDATER_INIT_RECORD; if (srcData == nullptr || dataLen == 0) { - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "srcData or dataLen is invalid"); return -1; } if (Init(srcData, dataLen) != 0) { PKG_LOGE("init pkcs7 data fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "init pkcs7 data fail"); return -1; } @@ -123,12 +125,12 @@ int32_t Pkcs7SignedData::Init(const uint8_t *sourceData, const uint32_t sourceDa BIO *p7Bio = BIO_new(BIO_s_mem()); if (p7Bio == nullptr) { PKG_LOGE("BIO_new error!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "BIO_new error!"); return -1; } if (static_cast(BIO_write(p7Bio, sourceData, sourceDataLen)) != sourceDataLen) { PKG_LOGE("BIO_write error!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "BIO_write error!"); BIO_free(p7Bio); return -1; } @@ -141,7 +143,7 @@ int32_t Pkcs7SignedData::Init(const uint8_t *sourceData, const uint32_t sourceDa if (pkcs7_ == nullptr) { PKG_LOGE("d2i_PKCS7_bio failed!"); BIO_free(p7Bio); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "d2i_PKCS7_bio failed!"); return -1; } @@ -149,14 +151,14 @@ int32_t Pkcs7SignedData::Init(const uint8_t *sourceData, const uint32_t sourceDa if (type != NID_pkcs7_signed) { PKG_LOGE("Invalid pkcs7 data type %d", type); BIO_free(p7Bio); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(type, "Invalid pkcs7 data type"); return -1; } BIO_free(p7Bio); if (CertVerify::GetInstance().Init() != 0) { PKG_LOGE("init cert verify fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1,"init cert verify fail"); return -1; } return 0; @@ -174,11 +176,12 @@ int32_t Pkcs7SignedData::Init(const uint8_t *sourceData, const uint32_t sourceDa */ int32_t Pkcs7SignedData::DoParse() { + Updater::UPDATER_INIT_RECORD; std::vector contentInfo; int32_t ret = ParseContentInfo(contentInfo); if (ret != 0) { PKG_LOGE("parse pkcs7 contentInfo fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "parse pkcs7 contentInfo fail"); return -1; } @@ -186,7 +189,7 @@ int32_t Pkcs7SignedData::DoParse() ret = GetDigestFromContentInfo(contentInfo); if (ret != 0) { PKG_LOGE("invalid pkcs7 contentInfo fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "invalid pkcs7 contentInfo fail"); return -1; } } @@ -209,25 +212,25 @@ int32_t Pkcs7SignedData::ParseContentInfo(std::vector &digestBlock) con PKCS7_SIGNED *signData = pkcs7_->d.sign; if (signData == nullptr) { PKG_LOGE("invalid pkcs7 signed data!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "invalid pkcs7 signed data!"); return -1; } PKCS7 *contentInfo = signData->contents; if (contentInfo == nullptr) { PKG_LOGE("pkcs7 content is nullptr!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "pkcs7 content is nullptr!"); return -1; } if (OBJ_obj2nid(contentInfo->type) != NID_pkcs7_data) { PKG_LOGE("invalid pkcs7 signed data type"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "invalid pkcs7 signed data type"); return -1; } if (GetASN1OctetStringData(contentInfo->d.data, digestBlock) != 0) { PKG_LOGE("get pkcs7 contentInfo fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "get pkcs7 contentInfo fail"); return -1; } @@ -239,7 +242,7 @@ int32_t Pkcs7SignedData::GetDigestFromContentInfo(std::vector &digestBl Updater::UPDATER_INIT_RECORD; if (digestBlock.size() <= sizeof(uint32_t)) { PKG_LOGE("invalid digest block info."); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "invalid digest block info."); return -1; } @@ -250,7 +253,7 @@ int32_t Pkcs7SignedData::GetDigestFromContentInfo(std::vector &digestBl offset += static_cast(sizeof(uint16_t)); if ((GetDigestLength(algoId) != digestLen) || ((digestLen + offset) != digestBlock.size())) { PKG_LOGE("invalid digestLen[%zu] and digestBlock len[%zu]", digestLen, digestBlock.size()); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "invalid digestLen[%zu] and digestBlock len[%zu]", digestLen, digestBlock.size()); return -1; } digest_.assign(digestBlock.begin() + offset, digestBlock.end()); @@ -309,25 +312,26 @@ int32_t Pkcs7SignedData::GetDigest(std::vector &digestBlock, int32_t Pkcs7SignedData::ReadSig(const uint8_t *sourceData, const uint32_t sourceDataLen, std::vector> &sigs) { + Updater::UPDATER_INIT_RECORD; if (sourceData == nullptr || sourceDataLen == 0) { - UPDATER_LAST_WORD(PKCS7_INVALID_PARAM_ERR); + UPDATER_LAST_WORD(PKCS7_INVALID_PARAM_ERR, "sourceData is nullptr or sourceDataLen is 0"); return PKCS7_INVALID_PARAM_ERR; } if (Init(sourceData, sourceDataLen) != 0) { PKG_LOGE("init pkcs7 data fail"); - UPDATER_LAST_WORD(PKCS7_INIT_ERR); + UPDATER_LAST_WORD(PKCS7_INIT_ERR, "init pkcs7 data fail"); return PKCS7_INIT_ERR; } STACK_OF(PKCS7_SIGNER_INFO) *p7SignerInfos = PKCS7_get_signer_info(pkcs7_); if (p7SignerInfos == nullptr) { PKG_LOGE("get pkcs7 signers failed!"); - UPDATER_LAST_WORD(PKCS7_INVALID_VALUE_ERR); + UPDATER_LAST_WORD(PKCS7_INVALID_VALUE_ERR, "get pkcs7 signers failed!"); return PKCS7_INVALID_VALUE_ERR; } int signerInfoNum = sk_PKCS7_SIGNER_INFO_num(p7SignerInfos); if (signerInfoNum <= 0) { PKG_LOGE("invalid signers info num %d!", signerInfoNum); - UPDATER_LAST_WORD(PKCS7_INVALID_VALUE_ERR); + UPDATER_LAST_WORD(PKCS7_INVALID_VALUE_ERR, "invalid signers info num %d!", signerInfoNum); return PKCS7_INVALID_VALUE_ERR; } for (int i = 0; i < signerInfoNum; i++) { @@ -342,7 +346,7 @@ int32_t Pkcs7SignedData::ReadSig(const uint8_t *sourceData, const uint32_t sourc } if (sigs.size() == 0) { PKG_LOGE("no valid sigs!"); - UPDATER_LAST_WORD(PKCS7_HAS_NO_VALID_SIG_ERR); + UPDATER_LAST_WORD(PKCS7_HAS_NO_VALID_SIG_ERR, "no valid sigs!"); return PKCS7_HAS_NO_VALID_SIG_ERR; } return PKCS7_SUCCESS; @@ -354,14 +358,14 @@ int32_t Pkcs7SignedData::SignerInfosParse() STACK_OF(PKCS7_SIGNER_INFO) *p7SignerInfos = PKCS7_get_signer_info(pkcs7_); if (p7SignerInfos == nullptr) { PKG_LOGE("get pkcs7 signers info failed!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "get pkcs7 signers info failed!"); return -1; } int signerInfoNum = sk_PKCS7_SIGNER_INFO_num(p7SignerInfos); if (signerInfoNum <= 0) { PKG_LOGE("invalid signers info num %d!", signerInfoNum); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "invalid signers info num %d!", signerInfoNum); return -1; } @@ -381,13 +385,14 @@ int32_t Pkcs7SignedData::SignerInfosParse() int32_t Pkcs7SignedData::SignerInfoParse(PKCS7_SIGNER_INFO *p7SignerInfo, Pkcs7SignerInfo &signerInfo) { + Updater::UPDATER_INIT_RECORD; if (p7SignerInfo == nullptr) { return -1; } PKCS7_ISSUER_AND_SERIAL *p7IssuerAndSerial = p7SignerInfo->issuer_and_serial; if (p7IssuerAndSerial == nullptr) { PKG_LOGE("signer cert info is nullptr!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "signer cert info is nullptr!"); return -1; } signerInfo.issuerName = p7IssuerAndSerial->issuer; @@ -416,27 +421,28 @@ int32_t Pkcs7SignedData::SignerInfoParse(PKCS7_SIGNER_INFO *p7SignerInfo, Pkcs7S int32_t Pkcs7SignedData::Pkcs7SignleSignerVerify(const Pkcs7SignerInfo &signerInfo, const std::vector &hash, const std::vector &sig) const { + Updater::UPDATER_INIT_RECORD; if (pkcs7_ == nullptr) { - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "pkcs7_ is nullptr"); return -1; } STACK_OF(X509) *certStack = pkcs7_->d.sign->cert; if (certStack == nullptr) { PKG_LOGE("certStack is empty!"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "certStack is empty!"); return -1; } X509 *cert = X509_find_by_issuer_and_serial(certStack, signerInfo.issuerName, signerInfo.serialNumber); if (cert == nullptr) { PKG_LOGE("cert is empty"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "cert is empty"); return -1; } if (CertVerify::GetInstance().CheckCertChain(certStack, cert) != 0) { PKG_LOGE("public cert check fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "public cert check fail"); return -1; } @@ -448,14 +454,14 @@ int32_t Pkcs7SignedData::VerifyDigest(X509 *cert, const Pkcs7SignerInfo &signer, { Updater::UPDATER_INIT_RECORD; if (cert == nullptr) { - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "cert is null"); return -1; } EVP_PKEY *pubKey = X509_get_pubkey(cert); if (pubKey == nullptr) { PKG_LOGE("get pubkey from cert fail"); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "get pubkey from cert fail"); return -1; } diff --git a/services/package/pkg_verify/pkg_verify_util.cpp b/services/package/pkg_verify/pkg_verify_util.cpp index 3dc251d9..4725e1af 100644 --- a/services/package/pkg_verify/pkg_verify_util.cpp +++ b/services/package/pkg_verify/pkg_verify_util.cpp @@ -38,6 +38,7 @@ constexpr uint32_t INTERCEPT_HASH_LENGTH = 8; int32_t PkgVerifyUtil::VerifySourceDigest(std::vector &signature, std::vector &sourceDigest, const std::string & keyPath) const { + Updater::UPDATER_INIT_RECORD; std::vector> sigs; Pkcs7SignedData pkcs7; SignAlgorithm::SignAlgorithmPtr signAlgorithm = PkgAlgorithmFactory::GetVerifyAlgorithm( @@ -57,8 +58,9 @@ int32_t PkgVerifyUtil::VerifySourceDigest(std::vector &signature, std:: int32_t PkgVerifyUtil::VerifyAccPackageSign(const PkgStreamPtr pkgStream, const std::string &keyPath) const { + Updater::UPDATER_INIT_RECORD; if (pkgStream == nullptr) { - UPDATER_LAST_WORD(PKG_INVALID_PARAM); + UPDATER_LAST_WORD(PKG_INVALID_PARAM, "pkgStream is null"); return PKG_INVALID_PARAM; } size_t signatureSize = 0; @@ -66,7 +68,7 @@ int32_t PkgVerifyUtil::VerifyAccPackageSign(const PkgStreamPtr pkgStream, const uint16_t commentTotalLenAll = 0; if (GetSignature(pkgStream, signatureSize, signature, commentTotalLenAll) != PKG_SUCCESS) { PKG_LOGE("get package signature fail!"); - UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE); + UPDATER_LAST_WORD(PKG_INVALID_SIGNATURE, "get package signature fail!"); return PKG_INVALID_SIGNATURE; } size_t srcDataLen = pkgStream->GetFileLength() - commentTotalLenAll -2; @@ -80,17 +82,18 @@ int32_t PkgVerifyUtil::VerifyAccPackageSign(const PkgStreamPtr pkgStream, const int32_t PkgVerifyUtil::VerifySign(std::vector &signData, std::vector &digest) const { + Updater::UPDATER_INIT_RECORD; std::vector hash; int32_t ret = Pkcs7verify(signData, hash); if (ret != PKG_SUCCESS) { PKG_LOGE("pkcs7 verify fail!"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "pkcs7 verify fail!"); return ret; } size_t hashLen = hash.size(); if ((hashLen != digest.size()) || memcmp(hash.data(), digest.data(), hashLen) != EOK) { PKG_LOGE("Failed to memcmp data."); - UPDATER_LAST_WORD(PKG_INVALID_DIGEST); + UPDATER_LAST_WORD(PKG_INVALID_DIGEST, "Failed to memcmp data."); return PKG_INVALID_DIGEST; } return PKG_SUCCESS; @@ -98,8 +101,9 @@ int32_t PkgVerifyUtil::VerifySign(std::vector &signData, std::vectorGetFileLength() - commentTotalLenAll - 2; @@ -135,12 +139,12 @@ int32_t PkgVerifyUtil::VerifyPackageSign(const PkgStreamPtr pkgStream, const std int32_t PkgVerifyUtil::GetSignature(const PkgStreamPtr pkgStream, size_t &signatureSize, std::vector &signature, uint16_t &commentTotalLenAll) const { - UPDATER_INIT_RECORD' + Updater::UPDATER_INIT_RECORD; size_t signatureStart = 0; int32_t ret = ParsePackage(pkgStream, signatureStart, signatureSize, commentTotalLenAll); if (ret != PKG_SUCCESS || signatureSize < PKG_FOOTER_SIZE) { PKG_LOGE("Parse package failed."); - UPDATER_LAST_WORD(-1); + UPDATER_LAST_WORD(-1, "Parse package failed."); return -1; } @@ -150,7 +154,7 @@ int32_t PkgVerifyUtil::GetSignature(const PkgStreamPtr pkgStream, size_t &signat ret = pkgStream->Read(signData, signatureStart, signDataLen, readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("read signature failed %s", pkgStream->GetFileName().c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "read signature failed " + pkgStream->GetFileName()); return ret; } signature.assign(signData.buffer, signData.buffer + readLen); @@ -168,6 +172,7 @@ int32_t PkgVerifyUtil::GetSignature(const PkgStreamPtr pkgStream, size_t &signat int32_t PkgVerifyUtil::ParsePackage(const PkgStreamPtr pkgStream, size_t &signatureStart, size_t &signatureSize, uint16_t &commentTotalLenAll) const { + Updater::UPDATER_INIT_RECORD; ZipPkgParse zipParse; PkgSignComment pkgSignComment {}; int32_t ret = zipParse.ParseZipPkg(pkgStream, pkgSignComment); diff --git a/services/package/pkg_verify/zip_pkg_parse.cpp b/services/package/pkg_verify/zip_pkg_parse.cpp index 07e9ca65..9f18e547 100644 --- a/services/package/pkg_verify/zip_pkg_parse.cpp +++ b/services/package/pkg_verify/zip_pkg_parse.cpp @@ -51,12 +51,12 @@ const uint8_t ZIP_EOCD_SIGNATURE_BIG_ENDIAN[4] = {0x50, 0x4b, 0x05, 0x06}; int32_t ZipPkgParse::DoParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSignComment, size_t &readLen, const uint16_t &signCommentAppendLen, uint16_t &signCommentTotalLen) const { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; size_t fileLen = pkgStream->GetFileLength(); size_t eocdTotalLen = ZIP_EOCD_FIXED_PART_LEN + signCommentTotalLen; if (fileLen <= eocdTotalLen) { PKG_LOGE("Invalid eocd len[%zu]", eocdTotalLen); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT, "Invalid eocd len[%zu]", eocdTotalLen); return PKG_INVALID_PKG_FORMAT; } @@ -65,14 +65,14 @@ int32_t ZipPkgParse::DoParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSi int32_t ret = pkgStream->Read(zipEocd, zipEocdStart, eocdTotalLen, readLen); if (ret != PKG_SUCCESS) { PKG_LOGE("read zip eocd failed %s", pkgStream->GetFileName().c_str()); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT, "read zip eocd failed " + pkgStream->GetFileName()); return ret; } ret = CheckZipEocd(zipEocd.buffer, eocdTotalLen, signCommentTotalLen); if (ret != PKG_SUCCESS) { PKG_LOGE("CheckZipEocd() error, ret[%d]", ret); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD(ret, "CheckZipEocd() error"); return ret; } @@ -89,9 +89,9 @@ int32_t ZipPkgParse::DoParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSi int32_t ZipPkgParse::ParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSignComment) const { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; if (pkgStream == nullptr) { - UPDATER_LAST_WORD(PKG_INVALID_PARAM); + UPDATER_LAST_WORD(PKG_INVALID_PARAM, "pkgStream is invalid"); return PKG_INVALID_PARAM; } size_t fileLen = pkgStream->GetFileLength(); @@ -116,7 +116,7 @@ int32_t ZipPkgParse::ParseZipPkg(PkgStreamPtr pkgStream, PkgSignComment &pkgSign ret = ParsePkgFooter(footer.buffer, PKG_FOOTER_SIZE, signCommentAppendLen, signCommentTotalLen); if (ret != PKG_SUCCESS) { PKG_LOGE("ParsePkgFooter() error, ret[%d]", ret); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "ParsePkgFooter() error"); return ret; } return DoParseZipPkg(pkgStream, pkgSignComment, readLen, signCommentAppendLen, signCommentTotalLen); @@ -164,14 +164,14 @@ int32_t ZipPkgParse::CheckZipEocd(const uint8_t *eocd, size_t length, Updater::UPDATER_INIT_RECORD; if (length < PKG_ZIP_EOCD_MIN_LEN) { PKG_LOGE("bad eocd length: append[0x%04X]", length); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD("bad eocd length", length); return PKG_INVALID_PKG_FORMAT; } uint32_t eocdSignature = ReadLE32(eocd); if (eocdSignature != ZIP_EOCD_SIGNATURE) { PKG_LOGE("bad zip eocd flag[%zu]", eocdSignature); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD("bad zip eocd flag", eocdSignature); return PKG_INVALID_PKG_FORMAT; } @@ -184,7 +184,7 @@ int32_t ZipPkgParse::CheckZipEocd(const uint8_t *eocd, size_t length, eocd[i + 2] == ZIP_EOCD_SIGNATURE_BIG_ENDIAN[2] && /* eocd[i + 2] = 0x05 */ eocd[i + 3] == ZIP_EOCD_SIGNATURE_BIG_ENDIAN[3]) { /* eocd[i + 3] = 0x06 */ PKG_LOGE("EOCD marker occurs after start of EOCD"); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT, "EOCD marker occurs after start of EOCD"); return PKG_INVALID_PKG_FORMAT; } } @@ -193,7 +193,7 @@ int32_t ZipPkgParse::CheckZipEocd(const uint8_t *eocd, size_t length, uint16_t tempLen = ReadLE16(zipSignCommentAddr); if (signCommentTotalLen != tempLen) { PKG_LOGE("compare sign comment length: eocd[0x%04X], footer[0x%04X] error", tempLen, signCommentTotalLen); - UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT); + UPDATER_LAST_WORD(PKG_INVALID_PKG_FORMAT, tempLen, signCommentTotalLen); return PKG_INVALID_PKG_FORMAT; } diff --git a/services/script/script_instruction/script_instructionhelper.cpp b/services/script/script_instruction/script_instructionhelper.cpp index 05cfacd5..8ec893ad 100644 --- a/services/script/script_instruction/script_instructionhelper.cpp +++ b/services/script/script_instruction/script_instructionhelper.cpp @@ -113,14 +113,14 @@ int32_t ScriptInstructionHelper::RegisterAddInstruction(const Uscript::UScriptIn int32_t ret = factory->CreateInstructionInstance(instr, instrName); if (ret != USCRIPT_SUCCESS || instr == nullptr) { USCRIPT_LOGE("Fail to create instruction for %s", instrName.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to create instruction", instrName); return ret == USCRIPT_SUCCESS ? USCRIPT_ERROR_CREATE_OBJ : USCRIPT_NOTEXIST_INSTRUCTION; } ret = AddInstruction(instrName, instr); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Fail to add instruction for %s", instrName.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to add instruction for ", instrName); // ret is USCRIPT_ERROR_REVERED, instr register failed, can be deleted delete instr; instr = nullptr; @@ -137,14 +137,14 @@ int32_t ScriptInstructionHelper::RegisterUserInstruction(const std::string& libN char *realPath = realpath(libName.c_str(), nullptr); if (realPath == nullptr) { USCRIPT_LOGE("realPath is NULL %s", libName.c_str()); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD("realPath is NUL", libName); return USCRIPT_INVALID_PARAM; } std::string realLibName = realPath; free(realPath); if (!userInstrLibName_.empty() && userInstrLibName_.compare(realLibName) != 0) { USCRIPT_LOGE("Lib name must be equal %s ", realLibName.c_str()); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD("Lib name must be equal", realLibName); return USCRIPT_INVALID_PARAM; } @@ -155,7 +155,7 @@ int32_t ScriptInstructionHelper::RegisterUserInstruction(const std::string& libN } if (instrLib_ == nullptr) { USCRIPT_LOGE("Fail to dlopen %s , dlerror: %s", libName.c_str(), dlerror()); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Fail to dlopen " + libName, dlerror()); return USCRIPT_INVALID_PARAM; } auto pGetInstructionFactory = @@ -164,13 +164,13 @@ int32_t ScriptInstructionHelper::RegisterUserInstruction(const std::string& libN (void(*)(Uscript::UScriptInstructionFactoryPtr))dlsym(instrLib_, "ReleaseInstructionFactory"); if (pReleaseInstructionFactory == nullptr || pGetInstructionFactory == nullptr) { USCRIPT_LOGE("Fail to get sym %s", libName.c_str()); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD("Fail to get sym", libName); return USCRIPT_INVALID_PARAM; } factory = pGetInstructionFactory(); if (factory == nullptr) { USCRIPT_LOGE("Fail to create instruction factory for %s", instrName.c_str()); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD("Fail to create instruction factory for", instrName); return USCRIPT_INVALID_PARAM; } ON_SCOPE_EXIT(freeFactory) { diff --git a/services/script/script_instruction/script_loadscript.cpp b/services/script/script_instruction/script_loadscript.cpp index 20709ade..d081bc5b 100644 --- a/services/script/script_instruction/script_loadscript.cpp +++ b/services/script/script_instruction/script_loadscript.cpp @@ -24,11 +24,11 @@ using namespace Uscript; namespace BasicInstruction { int32_t ScriptLoadScript::Execute(UScriptEnv &env, UScriptContext &context) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; ScriptInstructionHelper* helper = ScriptInstructionHelper::GetBasicInstructionHelper(); if (helper == nullptr) { USCRIPT_LOGE("Failed to get instruction helper"); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Failed to get instruction helper"); return USCRIPT_INVALID_PARAM; } @@ -37,13 +37,13 @@ int32_t ScriptLoadScript::Execute(UScriptEnv &env, UScriptContext &context) int32_t ret = context.GetParam(0, scriptName); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Failed to get param"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Failed to get scriptName"); return ret; } ret = context.GetParam(1, priority); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Failed to get param"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Failed to get priority"); return ret; } USCRIPT_LOGI("ScriptLoadScript %s priority:%d", scriptName.c_str(), priority); diff --git a/services/script/script_instruction/script_registercmd.cpp b/services/script/script_instruction/script_registercmd.cpp index 52245570..74f87b82 100644 --- a/services/script/script_instruction/script_registercmd.cpp +++ b/services/script/script_instruction/script_registercmd.cpp @@ -25,11 +25,11 @@ using namespace Uscript; namespace BasicInstruction { int32_t ScriptRegisterCmd::Execute(UScriptEnv &env, UScriptContext &context) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; ScriptInstructionHelper* helper = ScriptInstructionHelper::GetBasicInstructionHelper(); if (helper == nullptr) { USCRIPT_LOGE("Fail to get instruction helper"); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Fail to get instruction helper"); return USCRIPT_INVALID_PARAM; } @@ -38,13 +38,13 @@ int32_t ScriptRegisterCmd::Execute(UScriptEnv &env, UScriptContext &context) int32_t ret = context.GetParam(0, instrName); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Fail to get param"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to get instrName"); return ret; } ret = context.GetParam(1, libName); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Fail to get param"); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Fail to get libName"); return ret; } diff --git a/services/script/script_interpreter/script_interpreter.cpp b/services/script/script_interpreter/script_interpreter.cpp index 9ca1e87a..5da07235 100644 --- a/services/script/script_interpreter/script_interpreter.cpp +++ b/services/script/script_interpreter/script_interpreter.cpp @@ -28,7 +28,7 @@ static int32_t g_instanceId = 0; int32_t ScriptInterpreter::ExecuteScript(ScriptManagerImpl *manager, Hpackage::PkgManager::StreamPtr pkgStream) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; if (pkgStream == nullptr) { USCRIPT_LOGE("Param error"); UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); @@ -38,7 +38,7 @@ int32_t ScriptInterpreter::ExecuteScript(ScriptManagerImpl *manager, Hpackage::P auto inter = new (std::nothrow) ScriptInterpreter(manager); if (inter == nullptr) { USCRIPT_LOGE("Fail to create ScriptInterpreter for script %s", pkgStream->GetFileName().c_str()); - UPDATER_LAST_WORD(USCRIPT_ERROR_CREATE_OBJ); + UPDATER_LAST_WORD(USCRIPT_ERROR_CREATE_OBJ, pkgStream->GetFileName()); return USCRIPT_ERROR_CREATE_OBJ; } int32_t ret = inter->LoadScript(pkgStream); @@ -46,7 +46,7 @@ int32_t ScriptInterpreter::ExecuteScript(ScriptManagerImpl *manager, Hpackage::P delete inter; inter = nullptr; USCRIPT_LOGE("Fail to loadScript script %s", pkgStream->GetFileName().c_str()); - UPDATER_LAST_WORD(USCRIPT_ERROR_CREATE_OBJ); + UPDATER_LAST_WORD(ret, "Fail to loadScript script" + pkgStream->GetFileName); return ret; } ret = inter->Execute(); diff --git a/services/script/script_manager/script_managerImpl.cpp b/services/script/script_manager/script_managerImpl.cpp index 034322f0..d444c355 100644 --- a/services/script/script_manager/script_managerImpl.cpp +++ b/services/script/script_manager/script_managerImpl.cpp @@ -171,27 +171,27 @@ int32_t ScriptManagerImpl::ExtractAndExecuteScript(PkgManager::PkgManagerPtr man const FileInfo *info = manager->GetFileInfo(scriptName); if (info == nullptr) { USCRIPT_LOGE("Error to get file info"); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Error to get file info"); return USCRIPT_INVALID_PARAM; } int32_t ret = manager->CreatePkgStream(outStream, path + "/" + scriptName, info->unpackedSize, PkgStream::PkgStreamType_MemoryMap); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Failed to create script stream %s", scriptName.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Failed to create script stream " + scriptName); return ret; } ret = manager->ExtractFile(scriptName, outStream); if (ret != USCRIPT_SUCCESS) { manager->ClosePkgStream(outStream); USCRIPT_LOGE("Failed to extract script stream %s", scriptName.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Failed to extract script stream" + scriptName); return ret; } if (scriptVerifier_ == nullptr || !scriptVerifier_->VerifyHashData("build_tools/", scriptName, outStream)) { manager->ClosePkgStream(outStream); USCRIPT_LOGE("verify script %s by hash signed data failed", scriptName.c_str()); - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "verify script by hash signed data failed" + scriptName.c_str()); return USCRIPT_INVALID_SCRIPT; } ret = ScriptInterpreter::ExecuteScript(this, outStream); @@ -205,7 +205,7 @@ int32_t ScriptManagerImpl::ExtractAndExecuteScript(PkgManager::PkgManagerPtr man int32_t ScriptManagerImpl::ExecuteScript(int32_t priority) { - UPDATER_INIT_RECORD; + Updater::UPDATER_INIT_RECORD; if (priority >= MAX_PRIORITY || priority < 0) { USCRIPT_LOGE("ExecuteScript priority not support %d", priority); UPDATER_LAST_WORD(USCRIPT_INVALID_PRIORITY, priority); @@ -214,7 +214,7 @@ int32_t ScriptManagerImpl::ExecuteScript(int32_t priority) PkgManager::PkgManagerPtr manager = scriptEnv_->GetPkgManager(); if (manager == nullptr) { USCRIPT_LOGE("Failed to get pkg manager"); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Failed to get pkg manager"); return USCRIPT_INVALID_PARAM; } if (scriptFiles_[priority].size() == 0) { @@ -233,6 +233,7 @@ int32_t ScriptManagerImpl::ExecuteScript(int32_t priority) ret = ExtractAndExecuteScript(manager, scriptFiles_[priority][i]); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Failed to execute script %s", scriptFiles_[priority][i].c_str()); + UPDATER_LAST_WORD(ret, "Failed to execute script " + scriptFiles_[priority][i]); retCode = ret; } } @@ -267,13 +268,13 @@ int32_t ScriptManagerImpl::AddScript(const std::string &scriptName, int32_t prio PkgManager::PkgManagerPtr manager = scriptEnv_->GetPkgManager(); if (manager == nullptr) { USCRIPT_LOGE("Failed to get pkg manager"); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Failed to get pkg manager"); return USCRIPT_INVALID_PARAM; } if (manager->GetFileInfo(scriptName) == nullptr) { USCRIPT_LOGE("Failed to access script %s", scriptName.c_str()); - UPDATER_LAST_WORD(USCRIPT_INVALID_SCRIPT); + UPDATER_LAST_WORD(USCRIPT_INVALID_SCRIPT, "Failed to access script " + scriptName); return USCRIPT_INVALID_SCRIPT; } scriptFiles_[priority].push_back(scriptName); diff --git a/services/updater.cpp b/services/updater.cpp index f54a6cf3..074dca26 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -63,25 +63,26 @@ int g_tmpValue; int32_t ExtractUpdaterBinary(PkgManager::PkgManagerPtr manager, std::string &packagePath, const std::string &updaterBinary) { + UPDATER_INIT_RECORD; PkgManager::StreamPtr outStream = nullptr; int32_t ret = manager->CreatePkgStream(outStream, GetWorkPath() + updaterBinary, 0, PkgStream::PkgStreamType_Write); if (ret != PKG_SUCCESS) { LOG(ERROR) << "ExtractUpdaterBinary create stream fail"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "ExtractUpdaterBinary create stream fail"); return UPDATE_CORRUPT; } ret = manager->ExtractFile(updaterBinary, outStream); if (ret != PKG_SUCCESS) { LOG(ERROR) << "ExtractUpdaterBinary extract file failed"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "ExtractUpdaterBinary extract file failed"); return UPDATE_CORRUPT; } HashDataVerifier verifier {manager}; if (!verifier.LoadHashDataAndPkcs7(packagePath) || !verifier.VerifyHashData("build_tools/", updaterBinary, outStream)) { LOG(ERROR) << "verify updater_binary failed"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT,"verify updater_binary failed"); return UPDATE_CORRUPT; } manager->ClosePkgStream(outStream); @@ -109,7 +110,7 @@ UpdaterStatus IsSpaceCapacitySufficient(const UpdaterParams &upParams) std::vector stashSizeList = GetStashSizeList(upParams); if (stashSizeList.size() == 0) { LOG(ERROR) << "get stash size error"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "get stash size error"); return UPDATE_ERROR; } uint64_t maxStashSize = *max_element(stashSizeList.begin(), stashSizeList.end()); @@ -123,7 +124,7 @@ UpdaterStatus IsSpaceCapacitySufficient(const UpdaterParams &upParams) LOG(INFO) << "needed totalPkgSize = " << totalPkgSize; if (CheckStatvfs(totalPkgSize) != UPDATE_SUCCESS) { LOG(ERROR) << "CheckStatvfs error"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "CheckStatvfs error"); return UPDATE_ERROR; } return UPDATE_SUCCESS; @@ -131,22 +132,23 @@ UpdaterStatus IsSpaceCapacitySufficient(const UpdaterParams &upParams) static bool ConvertStrToLongLong(PkgManager::StreamPtr outStream, int64_t &value) { + UPDATER_INIT_RECORD; PkgBuffer data {}; if (outStream == nullptr) { LOG(ERROR) << "outStream is nullptr"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "outStream is nullptr"); return false; } outStream->GetBuffer(data); if (data.buffer == nullptr) { LOG(ERROR) << "data.buffer is nullptr"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "data.buffer is nullptr"); return false; } std::string str(reinterpret_cast(data.buffer), data.length); if (!Utils::ConvertToLongLong(str, value)) { LOG(ERROR) << "ConvertToLongLong failed"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "ConvertToLongLong failed"); return false; } return true; @@ -154,13 +156,14 @@ static bool ConvertStrToLongLong(PkgManager::StreamPtr outStream, int64_t &value std::vector GetStashSizeList(const UpdaterParams &upParams) { + UPDATER_INIT_RECORD; const std::string maxStashFileName = "all_max_stash"; std::vector stashSizeList; for (unsigned int i = upParams.pkgLocation; i < upParams.updatePackage.size(); i++) { PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance(); if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "pkgManager is nullptr"); return std::vector {}; } @@ -168,7 +171,7 @@ std::vector GetStashSizeList(const UpdaterParams &upParams) if (pkgManager->LoadPackageWithoutUnPack(upParams.updatePackage[i], fileIds) != PKG_SUCCESS) { LOG(ERROR) << "LoadPackageWithoutUnPack failed " << upParams.updatePackage[i]; PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "LoadPackageWithoutUnPack failed"); return std::vector {}; } @@ -186,20 +189,20 @@ std::vector GetStashSizeList(const UpdaterParams &upParams) if (outStream == nullptr || ret != PKG_SUCCESS) { LOG(ERROR) << "Create stream fail " << maxStashFileName << " in " << upParams.updatePackage[i]; PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "CreatePkgStream failed"); return std::vector {}; } if (pkgManager->ExtractFile(maxStashFileName, outStream) != PKG_SUCCESS) { LOG(ERROR) << "ExtractFile fail " << maxStashFileName << " in " << upParams.updatePackage[i]; PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "ExtractFile failed"); return std::vector {}; } int64_t maxStashSize = 0; if (!ConvertStrToLongLong(outStream, maxStashSize)) { PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "ConvertStrToLongLong failed"); return std::vector {}; } stashSizeList.push_back(static_cast(maxStashSize)); @@ -210,17 +213,18 @@ std::vector GetStashSizeList(const UpdaterParams &upParams) int CheckStatvfs(const uint64_t totalPkgSize) { + UPDATER_INIT_RECORD; struct statvfs64 updaterVfs; if (access("/sdcard/updater", 0) == 0) { if (statvfs64("/sdcard", &updaterVfs) < 0) { LOG(ERROR) << "Statvfs read /sdcard error!"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Statvfs read /sdcard error!"); return UPDATE_ERROR; } } else { if (statvfs64("/data", &updaterVfs) < 0) { LOG(ERROR) << "Statvfs read /data error!"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Statvfs read /data error!"); return UPDATE_ERROR; } } @@ -229,7 +233,7 @@ int CheckStatvfs(const uint64_t totalPkgSize) LOG(ERROR) << "Can not update, free space is not enough"; UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_SPACE_NOTENOUGH), true); UPDATER_UI_INSTANCE.Sleep(UI_SHOW_DURATION); - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Can not update, free space is not enough"); return UPDATE_ERROR; } return UPDATE_SUCCESS; @@ -275,13 +279,13 @@ UpdaterStatus DoInstallUpdaterPackage(PkgManager::PkgManagerPtr pkgManager, Upda UPDATER_UI_INSTANCE.ShowProgressPage(); if (upParams.callbackProgress == nullptr) { LOG(ERROR) << "CallbackProgress is nullptr"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "CallbackProgress is nullptr"); return UPDATE_CORRUPT; } upParams.callbackProgress(upParams.initialProgress * FULL_PERCENT_PROGRESS); if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "pkgManager is nullptr"); return UPDATE_CORRUPT; } @@ -289,7 +293,7 @@ UpdaterStatus DoInstallUpdaterPackage(PkgManager::PkgManagerPtr pkgManager, Upda upParams.sdExtMode == SDCARD_UPDATE_FROM_DATA || Utils::CheckUpdateMode(Updater::SDCARD_INTRAL_MODE) || Utils::CheckUpdateMode(Updater::FACTORY_INTERNAL_MODE)) != 0) { UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_SETPART_FAIL), true); - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "SetupPartitions failed"); return UPDATE_ERROR; } @@ -405,6 +409,7 @@ void HandleChildOutput(const std::string &buffer, int32_t bufferLen, bool &retry void ExcuteSubProc(const UpdaterParams &upParams, const std::string &fullPath, int pipeWrite) { + UPDATER_INIT_RECORD; // Set process scheduler to normal if current scheduler is // SCHED_FIFO, which may cause bad performance. int policy = syscall(SYS_sched_getscheduler, getpid()); @@ -423,17 +428,18 @@ void ExcuteSubProc(const UpdaterParams &upParams, const std::string &fullPath, i execl(fullPath.c_str(), fullPath.c_str(), upParams.updatePackage[upParams.pkgLocation].c_str(), std::to_string(pipeWrite).c_str(), retryPara.c_str(), nullptr); LOG(ERROR) << "Execute updater binary failed"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Execute updater binary failed"); exit(-1); } UpdaterStatus HandlePipeMsg(UpdaterParams &upParams, int pipeRead, bool &retryUpdate) { + UPDATER_INIT_RECORD; char buffer[MAX_BUFFER_SIZE] = {0}; FILE* fromChild = fdopen(pipeRead, "r"); if (fromChild == nullptr) { LOG(ERROR) << "fdopen pipeRead failed"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "fdopen pipeRead failed"); return UPDATE_ERROR; } while (fgets(buffer, MAX_BUFFER_SIZE - 1, fromChild) != nullptr) { @@ -483,12 +489,12 @@ UpdaterStatus StartUpdaterProc(PkgManager::PkgManagerPtr pkgManager, UpdaterPara int pfd[DEFAULT_PIPE_NUM]; /* communication between parent and child */ if (pipe(pfd) < 0) { LOG(ERROR) << "Create pipe failed: "; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Create pipe failed"); return UPDATE_ERROR; } if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "pkgManager is nullptr"); return UPDATE_CORRUPT; } @@ -532,6 +538,7 @@ UpdaterStatus StartUpdaterProc(PkgManager::PkgManagerPtr pkgManager, UpdaterPara close(pipeWrite); // close write endpoint bool retryUpdate = false; if (HandlePipeMsg(upParams, pipeRead, retryUpdate) != UPDATE_SUCCESS) { + UPDATER_LAST_WORD(UPDATE_ERROR, "HandlePipeMsg failed"); return UPDATE_ERROR; } diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 8dbec88d..50b7d661 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -401,7 +401,7 @@ bool UScriptInstructionBlockCheck::ExecReadBlockInfo(const std::string &devPath, int fd = open(devPath.c_str(), O_RDWR | O_LARGEFILE); if (fd == -1) { LOG(ERROR) << "Failed to open file"; - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD("Failed to open file", devPath); return false; } std::vector block_buff(H_BLOCK_SIZE); @@ -414,7 +414,7 @@ bool UScriptInstructionBlockCheck::ExecReadBlockInfo(const std::string &devPath, if (lseek64(fd, static_cast(it->first * H_BLOCK_SIZE), SEEK_SET) == -1) { LOG(ERROR) << "Failed to seek"; close(fd); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "Failed to seek"); return false; } size_t size = (it->second - it->first) * H_BLOCK_SIZE; @@ -422,7 +422,7 @@ bool UScriptInstructionBlockCheck::ExecReadBlockInfo(const std::string &devPath, if (!Utils::ReadFully(fd, block_buff.data() + pos, size)) { LOG(ERROR) << "Failed to read"; close(fd); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD(false, "Failed to read"); return false; } pos += size; @@ -448,7 +448,7 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: int32_t ret = context.GetParam(0, partitionName); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Failed to get param"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "Failed to get param " + partitionName); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context); } auto devPath = GetBlockDeviceByMountPoint(partitionName); @@ -457,7 +457,7 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: uint16_t mountCount = 0; if (devPath.empty() || (!ExecReadBlockInfo(devPath, context, mountTime, mountCount))) { LOG(ERROR) << "cannot get block device of partition"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, devPath); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context); } @@ -612,7 +612,7 @@ std::string UScriptInstructionShaCheck::CalculateBlockSha(const std::string &dev int fd = open(devPath.c_str(), O_RDWR | O_LARGEFILE); if (fd == -1) { LOG(ERROR) << "Failed to open file"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, devPath); return ""; } @@ -626,14 +626,14 @@ std::string UScriptInstructionShaCheck::CalculateBlockSha(const std::string &dev if (lseek64(fd, static_cast(it->first * H_BLOCK_SIZE), SEEK_SET) == -1) { LOG(ERROR) << "Failed to seek"; close(fd); - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "Failed to seek"); return ""; } for (size_t i = it->first; i < it->second; ++i) { if (!Utils::ReadFully(fd, block_buff.data(), H_BLOCK_SIZE)) { LOG(ERROR) << "Failed to read"; close(fd); - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "Failed to read"); return ""; } SHA256_Update(&ctx, block_buff.data(), H_BLOCK_SIZE); @@ -652,14 +652,14 @@ int32_t UScriptInstructionShaCheck::SetShaInfo(Uscript::UScriptContext &context, int32_t ret = context.GetParam(1, shaInfo.blockPairs); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Failed to get param blockPairs"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(ret, "Failed to get param blockPairs"); return USCRIPT_ERROR_EXECUTE; } ret = context.GetParam(SHA_CHECK_SECOND, shaInfo.contrastSha); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Failed to get param contrastSha"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(ret, "Failed to get param contrastSha"); return USCRIPT_ERROR_EXECUTE; } @@ -683,7 +683,7 @@ int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::U int32_t paramCount = context.GetParamCount(); if (paramCount != SHA_CHECK_PARAMS && paramCount != SHA_CHECK_TARGET_PARAMS) { LOG(ERROR) << "Invalid param"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Invalid param"); return ReturnAndPushParam(USCRIPT_INVALID_PARAM, context); } if (env.IsRetry() && !Utils::CheckFaultInfo(VERIFY_FAILED_REBOOT)) { @@ -694,7 +694,7 @@ int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::U int32_t ret = context.GetParam(0, partitionName); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Failed to get param"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "Failed to get param"); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context); } @@ -709,7 +709,7 @@ int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::U LOG(INFO) << "UScriptInstructionShaCheck::dev path : " << devPath; if (devPath.empty()) { LOG(ERROR) << "cannot get block device of partition"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "cannot get block device of partition"); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context); } ret = ExecReadShaInfo(env, devPath, shaInfo, partitionName); diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index d7252770..5a067636 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -177,7 +177,7 @@ int32_t USInstrImagePatch::ExecuteImagePatch(Uscript::UScriptEnv &env, Uscript:: ImagePatchPara para {}; int32_t ret = GetParam(context, para); if (ret != USCRIPT_SUCCESS) { - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "GetParam error"); LOG(ERROR) << "GetParam error"; return ret; } @@ -192,14 +192,14 @@ int32_t USInstrImagePatch::ExecuteImagePatch(Uscript::UScriptEnv &env, Uscript:: std::string srcFile = GetSourceFile(para); if (srcFile.empty()) { - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "get source file error"); LOG(ERROR) << "get source file error"; return USCRIPT_ERROR_EXECUTE; } UpdatePatch::MemMapInfo srcData {}; ret = UpdatePatch::PatchMapFile(srcFile, srcData); if (ret != 0) { - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Failed to mmap src file error"); LOG(ERROR) << "Failed to mmap src file error:" << ret; return -1; } @@ -207,7 +207,7 @@ int32_t USInstrImagePatch::ExecuteImagePatch(Uscript::UScriptEnv &env, Uscript:: PkgManager::StreamPtr patchStream = nullptr; ret = CreatePatchStream(env, para, patchStream); if (ret != USCRIPT_SUCCESS) { - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "CreatePatchStream error"); LOG(ERROR) << "CreatePatchStream error"; return USCRIPT_ERROR_EXECUTE; } @@ -292,14 +292,14 @@ int32_t USInstrImageShaCheck::ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript: CheckPara para {}; int32_t ret = GetParam(context, para); if (ret != USCRIPT_SUCCESS) { - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "GetParam error"); LOG(ERROR) << "GetParam error"; return ret; } ret = CheckHash(para); if (ret != USCRIPT_SUCCESS) { - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "CheckHash error"); env.PostMessage(UPDATER_RETRY_TAG, VERIFY_FAILED_REBOOT); LOG(ERROR) << "CheckHash error"; return ret; diff --git a/services/updater_binary/update_partitions.cpp b/services/updater_binary/update_partitions.cpp index 2b6241dc..4dd76aea 100644 --- a/services/updater_binary/update_partitions.cpp +++ b/services/updater_binary/update_partitions.cpp @@ -202,14 +202,14 @@ int32_t UpdatePartitions::Execute(Uscript::UScriptEnv &env, Uscript::UScriptCont LOG(INFO) << "enter UpdatePartitions::Execute "; if (context.GetParamCount() != 1) { LOG(ERROR) << "Invalid UpdatePartitions::Execute param"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Invalid UpdatePartitions::Execute param"); return USCRIPT_INVALID_PARAM; } std::string filePath; int32_t ret = context.GetParam(0, filePath); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Fail to get filePath"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(ret, "Fail to get filePath"); return USCRIPT_INVALID_PARAM; } else { LOG(INFO) << "UpdatePartitions::Execute filePath " << filePath; @@ -217,7 +217,7 @@ int32_t UpdatePartitions::Execute(Uscript::UScriptEnv &env, Uscript::UScriptCont const FileInfo *info = env.GetPkgManager()->GetFileInfo(filePath); if (info == nullptr) { LOG(ERROR) << "Error to get file info"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Error to get file info"); return USCRIPT_ERROR_EXECUTE; } return SetNewPartition(filePath, info, env); diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 233f1e7d..8fd0a9c1 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -152,7 +152,7 @@ bool UScriptInstructionRawImageWrite::WriteRawImage(const std::string &partition const FileInfo *info = env.GetPkgManager()->GetFileInfo(partitionName); if (info == nullptr) { LOG(ERROR) << "Error to get file info"; - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD("Error to get file info", partitionName); return false; } totalSize_ = info->unpackedSize; @@ -169,7 +169,7 @@ bool UScriptInstructionRawImageWrite::WriteRawImage(const std::string &partition partitionName, RawImageWriteProcessor, writer.get()); if (ret != USCRIPT_SUCCESS || outStream == nullptr) { LOG(ERROR) << "Error to create output stream"; - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD("Error to create output stream", partitionName); return false; } @@ -177,7 +177,7 @@ bool UScriptInstructionRawImageWrite::WriteRawImage(const std::string &partition if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to extract file"; env.GetPkgManager()->ClosePkgStream(outStream); - UPDATER_LAST_WORD(false); + UPDATER_LAST_WORD("Error to extract file", partitionName); return false; } env.GetPkgManager()->ClosePkgStream(outStream); @@ -191,7 +191,7 @@ int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscri int32_t ret = context.GetParam(0, partitionName); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to get partitionName"; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Error to get partitionName"); return ret; } @@ -206,7 +206,7 @@ int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscri LOG(INFO) << "UScriptInstructionRawImageWrite::Execute " << partitionName; if (env.GetPkgManager() == nullptr) { LOG(ERROR) << "Error to get pkg manager"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "UScriptInstructionRawImageWrite::Execute " + partitionName); return USCRIPT_ERROR_EXECUTE; } @@ -216,7 +216,7 @@ int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscri if (GetWritePathAndOffset(partitionName, writePath, offset, partitionSize) != USCRIPT_SUCCESS) { LOG(ERROR) << "Get partition:%s WritePathAndOffset fail \'" << partitionName.substr(1, partitionName.size()) << "\'."; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "GetWritePathAndOffset fail " + partitionName); return USCRIPT_ERROR_EXECUTE; } @@ -224,12 +224,12 @@ int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscri static_cast(&env), offset); if (writer == nullptr) { LOG(ERROR) << "Error to create writer"; - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "Error to create writer"); return USCRIPT_ERROR_EXECUTE; } if (!WriteRawImage(partitionName, writer, partitionSize, env)) { DataWriter::ReleaseDataWriter(writer); - UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE); + UPDATER_LAST_WORD(USCRIPT_ERROR_EXECUTE, "WriteRawImage failed"); return USCRIPT_ERROR_EXECUTE; } PartitionRecord::GetInstance().RecordPartitionUpdateStatus(partitionName, true); @@ -247,7 +247,7 @@ int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript: int32_t ret = context.GetParam(0, pkgFileName); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to get pkgFileName"; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Error to get pkgFileName"); return ret; } @@ -255,7 +255,7 @@ int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript: ret = context.GetParam(1, destPath); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to get destPath"; - UPDATER_LAST_WORD(ret); + UPDATER_LAST_WORD(ret, "Error to get destPath"); return ret; } @@ -263,14 +263,14 @@ int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript: PkgManager::PkgManagerPtr manager = env.GetPkgManager(); if (manager == nullptr) { LOG(ERROR) << "Error to get pkg manager"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Error to get pkg manager"); return USCRIPT_INVALID_PARAM; } const FileInfo *info = manager->GetFileInfo(pkgFileName); if (info == nullptr) { LOG(ERROR) << "Error to get file info"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD("Error to get file info", pkgFileName); return USCRIPT_INVALID_PARAM; } @@ -279,7 +279,7 @@ int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript: PkgStream::PkgStreamType_Write); if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to create output stream"; - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM, "Error to create output stream"); return USCRIPT_ERROR_EXECUTE; } @@ -287,7 +287,7 @@ int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript: if (ret != USCRIPT_SUCCESS) { LOG(ERROR) << "Error to extract file"; manager->ClosePkgStream(outStream); - UPDATER_LAST_WORD(USCRIPT_INVALID_PARAM); + UPDATER_LAST_WORD("Error to create output stream", pkgFileName); return USCRIPT_ERROR_EXECUTE; } @@ -390,13 +390,13 @@ int ExecUpdate(PkgManager::PkgManagerPtr pkgManager, int retry, const std::strin Hpackage::HashDataVerifier scriptVerifier {pkgManager}; if (!scriptVerifier.LoadHashDataAndPkcs7(pkgPath)) { LOG(ERROR) << "Fail to load hash data"; - UPDATER_LAST_WORD(EXIT_VERIFY_SCRIPT_ERROR); + UPDATER_LAST_WORD("LoadHashDataAndPkcs7 failed", pkgPath); return EXIT_VERIFY_SCRIPT_ERROR; } UpdaterEnv* env = new (std::nothrow) UpdaterEnv(pkgManager, postMessage, retry); if (env == nullptr) { LOG(ERROR) << "Fail to creat env"; - UPDATER_LAST_WORD(EXIT_PARSE_SCRIPT_ERROR); + UPDATER_LAST_WORD(EXIT_PARSE_SCRIPT_ERROR, "Fail to creat env"); return EXIT_PARSE_SCRIPT_ERROR; } int ret = 0; @@ -405,7 +405,7 @@ int ExecUpdate(PkgManager::PkgManagerPtr pkgManager, int retry, const std::strin LOG(ERROR) << "Fail to creat scriptManager"; ScriptManager::ReleaseScriptManager(); delete env; - UPDATER_LAST_WORD(EXIT_PARSE_SCRIPT_ERROR); + UPDATER_LAST_WORD(EXIT_PARSE_SCRIPT_ERROR, "Fail to creat scriptManager"); return EXIT_PARSE_SCRIPT_ERROR; } @@ -418,7 +418,7 @@ int ExecUpdate(PkgManager::PkgManagerPtr pkgManager, int retry, const std::strin ScriptManager::ReleaseScriptManager(); delete env; env = nullptr; - UPDATER_LAST_WORD(USCRIPT_ERROR_CREATE_THREAD); + UPDATER_LAST_WORD(USCRIPT_ERROR_CREATE_THREAD, "Fail to create progress thread"); return USCRIPT_ERROR_CREATE_THREAD; } @@ -478,7 +478,7 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const std::unique_ptr pipeWrite(fdopen(pipeFd, "w"), fclose); if (pipeWrite == nullptr) { LOG(ERROR) << "Fail to fdopen, err: " << strerror(errno); - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); + UPDATER_LAST_WORD(strerror(errno), "Fail to fdopen"); return EXIT_INVALID_ARGS; } int ret = -1; @@ -491,7 +491,7 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); + UPDATER_LAST_WORD(EXIT_INVALID_ARGS, "pkgManager is nullptr"); return EXIT_INVALID_ARGS; } @@ -500,7 +500,7 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const if (ret != PKG_SUCCESS) { LOG(ERROR) << "Fail to load package"; PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); + UPDATER_LAST_WORD("Fail to load package", packagePath, keyPath); return EXIT_INVALID_ARGS; } #ifdef UPDATER_USE_PTABLE diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 470fd6d4..4e3f573a 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -100,24 +100,24 @@ static int OtaUpdatePreCheck(PkgManager::PkgManagerPtr pkgManager, const std::st UPDATER_INIT_RECORD; if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "pkgManager is nullptr"); return UPDATE_CORRUPT; } char realPath[PATH_MAX + 1] = {0}; if (realpath(packagePath.c_str(), realPath) == nullptr) { LOG(ERROR) << "realpath error"; - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "realpath error"); return PKG_INVALID_FILE; } if (access(realPath, F_OK) != 0) { LOG(ERROR) << "package does not exist!"; - UPDATER_LAST_WORD(PKG_INVALID_FILE); + UPDATER_LAST_WORD(PKG_INVALID_FILE, "package does not exist!"); return PKG_INVALID_FILE; } int32_t ret = pkgManager->VerifyOtaPackage(packagePath); if (ret != PKG_SUCCESS) { - LOG(INFO) << "VerifyOtaPackage fail ret :"<< ret; + LOG(INFO) << "VerifyOtaPackage fail ret :" << ret; UPDATER_LAST_WORD("sign", ret); return ret; } @@ -141,13 +141,13 @@ static UpdaterStatus UpdatePreCheck(UpdaterParams &upParams, const std::string p if (GetUpdatePackageInfo(pkgManager, pkgPath) != PKG_SUCCESS) { PkgManager::ReleasePackageInstance(pkgManager); LOG(ERROR) << "Verify update bin file Fail!"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Verify update bin file Fail!"); return UPDATE_ERROR; } if (PreProcess::GetInstance().DoUpdatePreProcess(upParams, pkgManager) != PKG_SUCCESS) { PkgManager::ReleasePackageInstance(pkgManager); LOG(ERROR) << "Version Check Fail!"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Version Check Fail!"); return UPDATE_ERROR; } if (PreProcess::GetInstance().DoUpdateClear() != 0) { @@ -170,13 +170,14 @@ __attribute__((weak)) void UpdaterVerifyFailEntry(bool verifyret) static UpdaterStatus VerifyPackages(UpdaterParams &upParams) { + UPDATER_INIT_RECORD; LOG(INFO) << "Verify packages start..."; UPDATER_UI_INSTANCE.ShowProgressPage(); UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_VERIFYPKG)); if (upParams.callbackProgress == nullptr) { UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_VERIFYPKGFAIL), true); - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "upParams.callbackProgress is null"); return UPDATE_CORRUPT; } upParams.callbackProgress(0.0); @@ -208,7 +209,7 @@ static UpdaterStatus VerifyPackages(UpdaterParams &upParams) upParams.installTime[i] = endTime - startTime; } if (VerifySpecialPkgs(upParams) != PKG_SUCCESS) { - UPDATER_LAST_WORD(UPDATE_CORRUPT); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "VerifySpecialPkgs failed"); return UPDATE_CORRUPT; } ProgressSmoothHandler(UPDATER_UI_INSTANCE.GetCurrentPercent(), @@ -286,13 +287,14 @@ bool IsBatteryCapacitySufficient() UpdaterStatus InstallUpdaterPackage(UpdaterParams &upParams, PkgManager::PkgManagerPtr manager) { + UPDATER_INIT_RECORD; UpdaterStatus status = UPDATE_UNKNOWN; STAGE(UPDATE_STAGE_BEGIN) << "Install package"; if (upParams.retryCount == 0) { // First time enter updater, record retryCount in case of abnormal reset. if (!PartitionRecord::GetInstance().ClearRecordPartitionOffset()) { LOG(ERROR) << "ClearRecordPartitionOffset failed"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "ClearRecordPartitionOffset failed"); return UPDATE_ERROR; } SetMessageToMisc(upParams.miscCmd, upParams.retryCount + 1, "retry_count"); @@ -344,7 +346,7 @@ static UpdaterStatus CalcProgress(const UpdaterParams &upParams, pkgStartPosition.push_back(VERIFY_PERCENT); if (allPkgSize == 0) { LOG(ERROR) << "All packages's size is 0."; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "All packages's size is 0."); return UPDATE_ERROR; } int64_t startSize = 0; @@ -362,6 +364,7 @@ static UpdaterStatus CalcProgress(const UpdaterParams &upParams, static int CheckMountData() { + UPDATER_INIT_RECORD; constexpr int retryTime = 3; for (int i = 0; i < retryTime; i++) { if (SetupPartitions() == 0) { @@ -371,7 +374,7 @@ static int CheckMountData() Utils::UsSleep(DISPLAY_TIME); } UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_SETPART_FAIL), true); - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "retry mount userdata more than three times"); return UPDATE_ERROR; } @@ -404,13 +407,13 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) // Only handle UPATE_ERROR and UPDATE_SUCCESS here.Let package verify handle others. if (IsSpaceCapacitySufficient(upParams) == UPDATE_ERROR) { - UPDATER_LAST_WORD(status); + UPDATER_LAST_WORD(status, "space nott enough"); return status; } if (upParams.retryCount == 0 && !IsBatteryCapacitySufficient()) { UPDATER_UI_INSTANCE.ShowUpdInfo(TR(LOG_LOWPOWER)); UPDATER_UI_INSTANCE.Sleep(UI_SHOW_DURATION); - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "Battery is not sufficient for install package."); LOG(ERROR) << "Battery is not sufficient for install package."; return UPDATE_SKIP; } @@ -418,7 +421,7 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) #ifdef UPDATER_USE_PTABLE if (!PtablePreProcess::GetInstance().DoPtableProcess(upParams)) { LOG(ERROR) << "DoPtableProcess failed"; - UPDATER_LAST_WORD(UPDATE_ERROR); + UPDATER_LAST_WORD(UPDATE_ERROR, "DoPtableProcess failed"); return UPDATE_ERROR; } #endif @@ -427,6 +430,7 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) static UpdaterStatus DoInstallPackages(UpdaterParams &upParams, std::vector &pkgStartPosition) { + UPDATER_INIT_RECORD; UpdaterStatus status = UPDATE_UNKNOWN; if (upParams.pkgLocation == upParams.updatePackage.size()) { LOG(WARNING) << "all packages has been installed, directly return success"; @@ -454,7 +458,7 @@ static UpdaterStatus DoInstallPackages(UpdaterParams &upParams, std::vector Date: Tue, 31 Dec 2024 11:19:19 +0800 Subject: [PATCH 4/7] =?UTF-8?q?Signed-off-by:=20=E7=8E=8B=E4=BD=B3?= =?UTF-8?q?=E6=A0=8B=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix --- services/flow_update/update_bin/component_processor.cpp | 5 ++--- services/fs_manager/mount.cpp | 2 +- services/package/pkg_package/pkg_upgradefile.cpp | 2 +- services/package/pkg_verify/pkcs7_signed_data.cpp | 2 +- services/script/script_interpreter/script_interpreter.cpp | 2 +- services/script/script_manager/script_managerImpl.cpp | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/services/flow_update/update_bin/component_processor.cpp b/services/flow_update/update_bin/component_processor.cpp index 0c1a0b08..f2cfccc1 100644 --- a/services/flow_update/update_bin/component_processor.cpp +++ b/services/flow_update/update_bin/component_processor.cpp @@ -157,8 +157,7 @@ int32_t RawImgProcessor::PreProcess(Uscript::UScriptEnv &env) if (GetWritePathAndOffset(partitionName, writePath, offset, partitionSize) != USCRIPT_SUCCESS) { LOG(ERROR) << "Get partition:%s WritePathAndOffset fail \'" << partitionName.substr(1, partitionName.size()) << "\'."; - UPDATER_LAST_WORD("Get partition:%s WritePathAndOffset fail \'" << - partitionName.substr(1, partitionName.size()) << "\'."); + UPDATER_LAST_WORD("WritePathAndOffset fail", partitionName); return USCRIPT_ERROR_EXECUTE; } const FileInfo *info = env.GetPkgManager()->GetFileInfo(partitionName); @@ -170,7 +169,7 @@ int32_t RawImgProcessor::PreProcess(Uscript::UScriptEnv &env) #ifdef UPDATER_USE_PTABLE if (partitionSize < info->unpackedSize) { LOG(ERROR) << "partition size: " << partitionSize << " is short than image size: " << totalSize_; - UPDATER_LAST_WORD(partitionName, "partition size: " << partitionSize << " is short than image size: " << totalSize_); + UPDATER_LAST_WORD(partitionName, partitionSize, totalSize_); return USCRIPT_ERROR_EXECUTE; } #endif diff --git a/services/fs_manager/mount.cpp b/services/fs_manager/mount.cpp index e73b7a02..b638b655 100644 --- a/services/fs_manager/mount.cpp +++ b/services/fs_manager/mount.cpp @@ -340,7 +340,7 @@ int SetupPartitions(bool isMountData) } if (UmountForPath(mountPoint) != 0) { LOG(ERROR) << "Umount " << mountPoint << " failed"; - UPDATER_LAST_WORD(-1, "Umount " mountPoint + " failed"); + UPDATER_LAST_WORD(-1, "Umount " + mountPoint + " failed"); return -1; } } diff --git a/services/package/pkg_package/pkg_upgradefile.cpp b/services/package/pkg_package/pkg_upgradefile.cpp index 7e2899eb..75058896 100644 --- a/services/package/pkg_package/pkg_upgradefile.cpp +++ b/services/package/pkg_package/pkg_upgradefile.cpp @@ -456,7 +456,7 @@ int32_t UpgradePkgFile::LoadPackage(std::vector &fileNames, VerifyF GetUpgradeSignatureLen() + UPGRADE_RESERVE_LEN; if (fileLen < buffSize) { PKG_LOGE("Invalid file %s fileLen:%zu ", pkgStream_->GetFileName().c_str(), fileLen); - UPDATER_LAST_WORD(PKG_INVALID_STATE, "Invalid file " + pkgStream_->GetFileName().c_str(), fileLen); + UPDATER_LAST_WORD(PKG_INVALID_STATE, "Invalid file " + pkgStream_->GetFileName(), fileLen); return PKG_INVALID_FILE; } diff --git a/services/package/pkg_verify/pkcs7_signed_data.cpp b/services/package/pkg_verify/pkcs7_signed_data.cpp index ba20d886..fb38f77d 100644 --- a/services/package/pkg_verify/pkcs7_signed_data.cpp +++ b/services/package/pkg_verify/pkcs7_signed_data.cpp @@ -158,7 +158,7 @@ int32_t Pkcs7SignedData::Init(const uint8_t *sourceData, const uint32_t sourceDa BIO_free(p7Bio); if (CertVerify::GetInstance().Init() != 0) { PKG_LOGE("init cert verify fail"); - UPDATER_LAST_WORD(-1,"init cert verify fail"); + UPDATER_LAST_WORD(-1, "init cert verify fail"); return -1; } return 0; diff --git a/services/script/script_interpreter/script_interpreter.cpp b/services/script/script_interpreter/script_interpreter.cpp index 5da07235..c1dfa80e 100644 --- a/services/script/script_interpreter/script_interpreter.cpp +++ b/services/script/script_interpreter/script_interpreter.cpp @@ -46,7 +46,7 @@ int32_t ScriptInterpreter::ExecuteScript(ScriptManagerImpl *manager, Hpackage::P delete inter; inter = nullptr; USCRIPT_LOGE("Fail to loadScript script %s", pkgStream->GetFileName().c_str()); - UPDATER_LAST_WORD(ret, "Fail to loadScript script" + pkgStream->GetFileName); + UPDATER_LAST_WORD(ret, "Fail to loadScript script" + pkgStream->GetFileName()); return ret; } ret = inter->Execute(); diff --git a/services/script/script_manager/script_managerImpl.cpp b/services/script/script_manager/script_managerImpl.cpp index d444c355..f2b5f409 100644 --- a/services/script/script_manager/script_managerImpl.cpp +++ b/services/script/script_manager/script_managerImpl.cpp @@ -191,7 +191,7 @@ int32_t ScriptManagerImpl::ExtractAndExecuteScript(PkgManager::PkgManagerPtr man if (scriptVerifier_ == nullptr || !scriptVerifier_->VerifyHashData("build_tools/", scriptName, outStream)) { manager->ClosePkgStream(outStream); USCRIPT_LOGE("verify script %s by hash signed data failed", scriptName.c_str()); - UPDATER_LAST_WORD(ret, "verify script by hash signed data failed" + scriptName.c_str()); + UPDATER_LAST_WORD(ret, "verify script by hash signed data failed" + scriptName); return USCRIPT_INVALID_SCRIPT; } ret = ScriptInterpreter::ExecuteScript(this, outStream); -- Gitee From 14004f6d21fbe93d96e38a5746e60ec4316ddcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=A0=8B?= Date: Tue, 31 Dec 2024 15:04:47 +0800 Subject: [PATCH 5/7] =?UTF-8?q?Signed-off-by:=20=E7=8E=8B=E4=BD=B3?= =?UTF-8?q?=E6=A0=8B=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix --- .../package/pkg_manager/pkg_managerImpl.cpp | 3 +- services/updater.cpp | 39 +++++++++++-------- services/updater_binary/update_processor.cpp | 3 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index fb595b76..d0f03b12 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -296,8 +296,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::s PkgFile::PkgType pkgType = GetPkgTypeByName(packagePath); unzipToFile_ = ((pkgType == PkgFile::PKG_TYPE_GZIP) ? true : unzipToFile_); if (pkgType == PkgFile::PKG_TYPE_UPGRADE) { - int32_t ret = LoadPackage(packagePath, fileIds, pkgType); - if (ret != PKG_SUCCESS) { + if (LoadPackage(packagePath, fileIds, pkgType) != PKG_SUCCESS) { ClearPkgFile(); UPDATER_LAST_WORD(ret, "LoadPackage failed"); PKG_LOGE("Parse %s fail ", packagePath.c_str()); diff --git a/services/updater.cpp b/services/updater.cpp index 074dca26..b37ea852 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -43,6 +43,7 @@ #ifdef UPDATER_USE_PTABLE #include "ptable_parse/ptable_manager.h" #endif +#include "scope_guard.h" #include "updater/hwfault_retry.h" #include "updater/updater_preprocess.h" #include "updater/updater_const.h" @@ -82,7 +83,7 @@ int32_t ExtractUpdaterBinary(PkgManager::PkgManagerPtr manager, std::string &pac if (!verifier.LoadHashDataAndPkcs7(packagePath) || !verifier.VerifyHashData("build_tools/", updaterBinary, outStream)) { LOG(ERROR) << "verify updater_binary failed"; - UPDATER_LAST_WORD(UPDATE_CORRUPT,"verify updater_binary failed"); + UPDATER_LAST_WORD(UPDATE_CORRUPT, "verify updater_binary failed"); return UPDATE_CORRUPT; } manager->ClosePkgStream(outStream); @@ -166,11 +167,13 @@ std::vector GetStashSizeList(const UpdaterParams &upParams) UPDATER_LAST_WORD(UPDATE_CORRUPT, "pkgManager is nullptr"); return std::vector {}; } + ON_SCOPE_EXIT(releasePackage) { + PkgManager::ReleasePackageInstance(pkgManager); + } std::vector fileIds; if (pkgManager->LoadPackageWithoutUnPack(upParams.updatePackage[i], fileIds) != PKG_SUCCESS) { LOG(ERROR) << "LoadPackageWithoutUnPack failed " << upParams.updatePackage[i]; - PkgManager::ReleasePackageInstance(pkgManager); UPDATER_LAST_WORD(UPDATE_CORRUPT, "LoadPackageWithoutUnPack failed"); return std::vector {}; } @@ -179,7 +182,6 @@ std::vector GetStashSizeList(const UpdaterParams &upParams) if (info == nullptr) { LOG(INFO) << "all_max_stash not exist " << upParams.updatePackage[i]; stashSizeList.push_back(0); - PkgManager::ReleasePackageInstance(pkgManager); continue; } @@ -188,20 +190,17 @@ std::vector GetStashSizeList(const UpdaterParams &upParams) PkgStream::PkgStreamType_MemoryMap); if (outStream == nullptr || ret != PKG_SUCCESS) { LOG(ERROR) << "Create stream fail " << maxStashFileName << " in " << upParams.updatePackage[i]; - PkgManager::ReleasePackageInstance(pkgManager); UPDATER_LAST_WORD(UPDATE_CORRUPT, "CreatePkgStream failed"); return std::vector {}; } if (pkgManager->ExtractFile(maxStashFileName, outStream) != PKG_SUCCESS) { LOG(ERROR) << "ExtractFile fail " << maxStashFileName << " in " << upParams.updatePackage[i]; - PkgManager::ReleasePackageInstance(pkgManager); UPDATER_LAST_WORD(UPDATE_CORRUPT, "ExtractFile failed"); return std::vector {}; } int64_t maxStashSize = 0; if (!ConvertStrToLongLong(outStream, maxStashSize)) { - PkgManager::ReleasePackageInstance(pkgManager); UPDATER_LAST_WORD(UPDATE_CORRUPT, "ConvertStrToLongLong failed"); return std::vector {}; } @@ -483,6 +482,22 @@ UpdaterStatus CheckProcStatus(pid_t pid, bool retryUpdate) return UPDATE_SUCCESS; } +static std::string GetBinaryPath() +{ + std::string fullPath = GetWorkPath() + std::string(UPDATER_BINARY); + (void)Utils::DeleteFile(fullPath); + + if (ExtractUpdaterBinary(pkgManager, upParams.updatePackage[upParams.pkgLocation], UPDATER_BINARY) != 0) { + LOG(INFO) << "There is no valid updater_binary in package, use updater_binary in device"; + fullPath = "/bin/updater_binary"; + } + +#ifdef UPDATER_UT + fullPath = "/data/updater/updater_binary"; +#endif + return fullPath; +} + UpdaterStatus StartUpdaterProc(PkgManager::PkgManagerPtr pkgManager, UpdaterParams &upParams) { UPDATER_INIT_RECORD; @@ -500,17 +515,7 @@ UpdaterStatus StartUpdaterProc(PkgManager::PkgManagerPtr pkgManager, UpdaterPara int pipeRead = pfd[0]; int pipeWrite = pfd[1]; - std::string fullPath = GetWorkPath() + std::string(UPDATER_BINARY); - (void)Utils::DeleteFile(fullPath); - - if (ExtractUpdaterBinary(pkgManager, upParams.updatePackage[upParams.pkgLocation], UPDATER_BINARY) != 0) { - LOG(INFO) << "There is no valid updater_binary in package, use updater_binary in device"; - fullPath = "/bin/updater_binary"; - } - -#ifdef UPDATER_UT - fullPath = "/data/updater/updater_binary"; -#endif + std::string fullPath = GetBinaryPath(); if (chmod(fullPath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { LOG(ERROR) << "Failed to change mode"; diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 8fd0a9c1..0c8f99e3 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -197,8 +197,7 @@ int32_t UScriptInstructionRawImageWrite::Execute(Uscript::UScriptEnv &env, Uscri if (env.IsRetry()) { LOG(DEBUG) << "Retry updater, check if current partition updated already during last time"; - bool isUpdated = PartitionRecord::GetInstance().IsPartitionUpdated(partitionName); - if (isUpdated) { + if (PartitionRecord::GetInstance().IsPartitionUpdated(partitionName)) { LOG(INFO) << partitionName << " already updated, skip"; return USCRIPT_SUCCESS; } -- Gitee From 6a06cecd2b28789d6487508982180fd5d7f27754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=A0=8B?= Date: Tue, 31 Dec 2024 07:33:30 +0000 Subject: [PATCH 6/7] update services/package/pkg_manager/pkg_managerImpl.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王佳栋 --- services/package/pkg_manager/pkg_managerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index d0f03b12..b7003ad7 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -298,7 +298,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::s if (pkgType == PkgFile::PKG_TYPE_UPGRADE) { if (LoadPackage(packagePath, fileIds, pkgType) != PKG_SUCCESS) { ClearPkgFile(); - UPDATER_LAST_WORD(ret, "LoadPackage failed"); + UPDATER_LAST_WORD("LoadPackage failed", packagePath); PKG_LOGE("Parse %s fail ", packagePath.c_str()); return ret; } -- Gitee From 3e9a83e9d552317ed4f241cd3e709dd8bfaace1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=A0=8B?= Date: Tue, 31 Dec 2024 08:36:57 +0000 Subject: [PATCH 7/7] update services/package/pkg_manager/pkg_managerImpl.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王佳栋 --- services/package/pkg_manager/pkg_managerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index b7003ad7..ccd8722e 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -300,7 +300,7 @@ int32_t PkgManagerImpl::LoadPackage(const std::string &packagePath, const std::s ClearPkgFile(); UPDATER_LAST_WORD("LoadPackage failed", packagePath); PKG_LOGE("Parse %s fail ", packagePath.c_str()); - return ret; + return PKG_INVALID_FILE; } } else if (pkgType != PkgFile::PKG_TYPE_NONE) { std::vector innerFileNames; -- Gitee