From aa923b2f3475d1bef8d4f2bfac09e106ad8fab27 Mon Sep 17 00:00:00 2001 From: yang-jingbo1985 Date: Fri, 17 Nov 2023 09:50:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=87=E4=BB=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E4=B8=8D=E9=99=90=E5=88=B6=E5=AD=97=E6=AF=8D=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E6=96=87=E4=BB=B6=E5=90=8D=20Signed-off-by:=20yangjin?= =?UTF-8?q?gbo10=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I775f4cc2d4b2593314d9be34a95aa681901fe0cb --- frameworks/native/backup_ext/src/ext_extension.cpp | 6 +++--- services/backup_sa/src/module_ipc/service.cpp | 14 +++++++------- tools/backup_tool/src/tools_op_backup.cpp | 4 ++-- tools/backup_tool/src/tools_op_restore.cpp | 8 ++++---- tools/backup_tool/src/tools_op_restore_async.cpp | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 31fe0acf2..485f0b643 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -78,8 +78,8 @@ UniqueFd BackupExtExtension::GetFileHandle(const string &fileName) VerifyCaller(); - if (!regex_match(fileName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::EXT_INVAL_ARG, "Filename is not alphanumeric"); + if (fileName.find('/') != string::npos) { + throw BError(BError::Codes::EXT_INVAL_ARG, "Filename is not valid"); } string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); @@ -226,7 +226,7 @@ static bool IsUserTar(const string &tarFile, const string &indexFile) auto cache = cachedEntity.Structuralize(); auto info = cache.GetExtManageInfo(); for (auto &item : info) { - if (item.fileName == tarFile) { + if (item.hashName == tarFile) { HILOGI("tarFile:%{public}s isUserTar:%{public}d", tarFile.data(), item.isUserTar); return item.isUserTar; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 3fe8dd7e0..2927e738d 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -352,8 +352,8 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) sched_->Sched(fileInfo.owner); return BError(BError::Codes::OK); } - if (!regex_match(fileInfo.fileName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not alphanumeric"); + if (fileInfo.fileName.find('/') != string::npos) { + throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); } auto backUpConnection = session_->GetExtConnection(fileInfo.owner); @@ -384,8 +384,8 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd) try { HILOGI("Begin"); string callerName = VerifyCallerAndGetCallerName(); - if (!regex_match(fileName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not alphanumeric"); + if (fileName.find('/') != string::npos) { + throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { fd = session_->OnBunleExtManageInfo(callerName, move(fd)); @@ -504,7 +504,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) try { HILOGI("Begin"); VerifyCaller(IServiceReverse::Scenario::RESTORE); - if (fileName == BConstants::RESTORE_INSTALL_PATH && regex_match(bundleName, regex("^[0-9a-zA-Z_.]+$"))) { + if (fileName == BConstants::RESTORE_INSTALL_PATH && bundleName.find('/') == string::npos) { session_->SetInstallState(bundleName, string(BConstants::RESTORE_INSTALL_PATH)); auto action = session_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::INSTALLING) { @@ -512,8 +512,8 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) } return BError(BError::Codes::OK); } - if (!regex_match(fileName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not alphanumeric"); + if (fileName.find('/') != string::npos) { + throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); } SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); session_->SetExtFileNameRequest(bundleName, fileName); diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index c85c557bf..2d0a4657c 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -132,8 +132,8 @@ static void OnFileReady(shared_ptr ctx, const BFileInfo &fileInfo, Uniq if (access(tmpPath.data(), F_OK) != 0 && mkdir(tmpPath.data(), S_IRWXU) != 0) { throw BError(BError::Codes::TOOL_INVAL_ARG, generic_category().message(errno)); } - if (!regex_match(fileInfo.fileName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not alphanumeric"); + if (fileInfo.fileName.find('/') != string::npos) { + throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not valid"); } UniqueFd fdLocal(open((tmpPath + "/" + fileInfo.fileName).data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU)); if (fdLocal < 0) { diff --git a/tools/backup_tool/src/tools_op_restore.cpp b/tools/backup_tool/src/tools_op_restore.cpp index 53c1b301b..90c3538c3 100644 --- a/tools/backup_tool/src/tools_op_restore.cpp +++ b/tools/backup_tool/src/tools_op_restore.cpp @@ -131,9 +131,9 @@ static void OnFileReady(shared_ptr ctx, const BFileInfo &fileInfo, Uniq { printf("FileReady owner = %s, fileName = %s, sn = %u, fd = %d\n", fileInfo.owner.c_str(), fileInfo.fileName.c_str(), fileInfo.sn, fd.Get()); - if (!regex_match(fileInfo.fileName, regex("^[0-9a-zA-Z_.]+$")) && + if (fileInfo.fileName.find('/') != string::npos && fileInfo.fileName != BConstants::RESTORE_INSTALL_PATH) { - throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not alphanumeric"); + throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not valid"); } string tmpPath; if (fileInfo.fileName == BConstants::RESTORE_INSTALL_PATH) { @@ -208,8 +208,8 @@ static void RestoreApp(shared_ptr restore, vector &bundleNa throw BError(BError::Codes::TOOL_INVAL_ARG, generic_category().message(errno)); } for (auto &bundleName : bundleNames) { - if (!regex_match(bundleName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::TOOL_INVAL_ARG, "bundleName is not alphanumeric"); + if (bundleName.find('/') != string::npos) { + throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not valid"); } string path = string(BConstants::BACKUP_TOOL_RECEIVE_DIR) + bundleName; if (access(path.data(), F_OK) != 0) { diff --git a/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index 18e1683a7..6869963ec 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -81,9 +81,9 @@ static void OnFileReady(shared_ptr ctx, const BFileInfo &fileInfo, { printf("FileReady owner = %s, fileName = %s, sn = %u, fd = %d\n", fileInfo.owner.c_str(), fileInfo.fileName.c_str(), fileInfo.sn, fd.Get()); - if (!regex_match(fileInfo.fileName, regex("^[0-9a-zA-Z_.]+$")) && + if (fileInfo.fileName.find('/') != string::npos && fileInfo.fileName != BConstants::RESTORE_INSTALL_PATH) { - throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not alphanumeric"); + throw BError(BError::Codes::TOOL_INVAL_ARG, "Filename is not valid"); } string tmpPath; if (fileInfo.fileName == BConstants::RESTORE_INSTALL_PATH) { @@ -144,8 +144,8 @@ static void RestoreApp(shared_ptr restore, vector &bun throw BError(BError::Codes::TOOL_INVAL_ARG, generic_category().message(errno)); } for (auto &bundleName : bundleNames) { - if (!regex_match(bundleName, regex("^[0-9a-zA-Z_.]+$"))) { - throw BError(BError::Codes::TOOL_INVAL_ARG, "bundleName is not alphanumeric"); + if (bundleName.find('/') != string::npos) { + throw BError(BError::Codes::TOOL_INVAL_ARG, "bundleName is not valid"); } string path = string(BConstants::BACKUP_TOOL_RECEIVE_DIR) + bundleName; if (access(path.data(), F_OK) != 0) { -- Gitee