diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 31fe0acf27fc799fdabef4b749179882c3ff35cd..485f0b64346c3eac8320ad221c9341a9df502bc8 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 3fe8dd7e0df51347af654678228f4fa268a3a392..2927e738ddf9a165c0a1eb0a539f42608d1acdb6 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 c85c557bf865c253eb257559ffc82389a487930c..2d0a4657c0c284855ca6388642dc2a02ecacf580 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 53c1b301b32ee49f3cf9f4a13f66178cbf2768c7..90c3538c3c2c04ec2cd575141b3e614c70b62fbc 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 18e1683a7d71a47da95cc2a6eee20297aa7c42e9..6869963eca88766141aad401bfec87f9caea6f1c 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) {