敏感信息打印+变量上锁

Signed-off-by: 17333770736 <jiatuo@huawei.com>
This commit is contained in:
17333770736 2024-08-26 17:08:17 +08:00
parent 2701b8f499
commit 499355e138
4 changed files with 28 additions and 18 deletions

View File

@ -71,7 +71,7 @@ bool IsValidPath(const std::string &inFilePath, std::string &realFilePath)
char path[PATH_MAX + 1] = { 0 };
if (inFilePath.empty() || inFilePath.length() > PATH_MAX || inFilePath.length() + 1 > MAX_CONFIG_PATH_LEN ||
realpath(inFilePath.c_str(), path) == nullptr) {
HILOGE("Get continue config file real path fail, inFilePath %{public}s.", inFilePath.c_str());
HILOGE("Get continue config file real path fail, inFilePath %{public}s.", GetAnonymStr(inFilePath).c_str());
return false;
}
@ -81,11 +81,11 @@ bool IsValidPath(const std::string &inFilePath, std::string &realFilePath)
return false;
}
if (!std::filesystem::exists(realFilePath)) {
HILOGE("The real file path %{public}s does not exist in the file system.", realFilePath.c_str());
HILOGE("The real file path %{public}s does not exist in the file system.", GetAnonymStr(realFilePath).c_str());
realFilePath = "";
return false;
}
HILOGI("The real file path %{public}s exist in the file system.", realFilePath.c_str());
HILOGI("The real file path %{public}s exist in the file system.", GetAnonymStr(realFilePath).c_str());
return true;
}
@ -132,37 +132,38 @@ bool UpdateAllowAppList(const std::string &cfgJsonStr)
int32_t LoadContinueConfig()
{
HILOGI("Load continue config, isMissContinueCfg %{public}d, ContinueCfgFullPath %{public}s.",
g_isMissContinueCfg.load(), g_continueCfgFullPath.c_str());
g_isMissContinueCfg.load(), GetAnonymStr(g_continueCfgFullPath).c_str());
std::string tempPath = g_continueCfgFullPath;
if (!g_isMissContinueCfg.load() &&
(g_continueCfgFullPath.empty() || !IsValidPath(tempPath, g_continueCfgFullPath))) {
char cfgPathBuf[MAX_CONFIG_PATH_LEN] = { 0 };
char *filePath = GetOneCfgFile(CONTINUE_CONFIG_RELATIVE_PATH.c_str(), cfgPathBuf, MAX_CONFIG_PATH_LEN);
if (filePath == nullptr || filePath != cfgPathBuf) {
HILOGI("Not find continue config file, relative path %{public}s.", CONTINUE_CONFIG_RELATIVE_PATH.c_str());
HILOGI("Not find continue config file, relative path %{public}s.",
GetAnonymStr(CONTINUE_CONFIG_RELATIVE_PATH).c_str());
g_isMissContinueCfg.store(true);
g_continueCfgFullPath = "";
return ERR_OK;
}
g_isMissContinueCfg.store(false);
g_continueCfgFullPath = std::string(filePath);
HILOGI("Get Continue config file full path success, cfgFullPath %{public}s.", g_continueCfgFullPath.c_str());
HILOGI("Get Continue config file full path success, cfgFullPath %{public}s.",
GetAnonymStr(g_continueCfgFullPath).c_str());
}
if (g_isMissContinueCfg.load()) {
HILOGI("Current device does not carry continue config file.");
return ERR_OK;
}
tempPath = g_continueCfgFullPath;
std::string anonymPath = GetAnonymStr(g_continueCfgFullPath);
if (!IsValidPath(tempPath, g_continueCfgFullPath)) {
HILOGE("Continue config full path is invalid, cfgFullPath %{public}s.", g_continueCfgFullPath.c_str());
HILOGE("Continue config full path is invalid, cfgFullPath %{public}s.", anonymPath.c_str());
return DMS_PERMISSION_DENIED;
}
std::ifstream in;
in.open(g_continueCfgFullPath.c_str(), std::ios::binary | std::ios::in);
if (!in.is_open()) {
HILOGE("Open continue config json file fail, cfgFullPath %{public}s.", g_continueCfgFullPath.c_str());
HILOGE("Open continue config json file fail, cfgFullPath %{public}s.", anonymPath.c_str());
return DMS_PERMISSION_DENIED;
}
@ -174,11 +175,11 @@ int32_t LoadContinueConfig()
in.close();
if (!UpdateAllowAppList(cfgFileContent)) {
HILOGE("Update allow app list fail, cfgFullPath %{public}s.", g_continueCfgFullPath.c_str());
HILOGE("Update allow app list fail, cfgFullPath %{public}s.", anonymPath.c_str());
return DMS_PERMISSION_DENIED;
}
HILOGI("Load continue config success, isMissContinueCfg %{public}d, cfgFullPath %{public}s.",
g_isMissContinueCfg.load(), g_continueCfgFullPath.c_str());
g_isMissContinueCfg.load(), anonymPath.c_str());
return ERR_OK;
}
@ -193,12 +194,12 @@ bool CheckBundleContinueConfig(const std::string &bundleName)
auto it = std::find(g_allowAppList.begin(), g_allowAppList.end(), bundleName);
if (it == g_allowAppList.end()) {
HILOGE("Current app is not allow to continue in config file, bundleName %{public}s, cfgPath %{public}s.",
bundleName.c_str(), g_continueCfgFullPath.c_str());
bundleName.c_str(), GetAnonymStr(g_continueCfgFullPath).c_str());
return false;
}
HILOGI("Current app is allow to continue in config file, bundleName %{public}s, cfgPath %{public}s.",
bundleName.c_str(), g_continueCfgFullPath.c_str());
bundleName.c_str(), GetAnonymStr(g_continueCfgFullPath).c_str());
return true;
}

View File

@ -48,6 +48,7 @@ private:
std::thread eventThread_;
std::condition_variable eventCon_;
std::mutex eventMutex_;
std::mutex softbusAdapterListenerMutex_;
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_ = nullptr;
};
} // namespace DistributedSchedule

View File

@ -93,14 +93,16 @@ int32_t DSchedAllConnectManager::GetServiceCollaborationManagerProxy()
#endif
char path[PATH_MAX + 1] = {0};
if (resolvedPath.length() > PATH_MAX || realpath(resolvedPath.c_str(), path) == nullptr) {
HILOGE("Check all connect so real path failed, resolvedPath [%{public}s].", resolvedPath.c_str());
HILOGE("Check all connect so real path failed, resolvedPath [%{public}s].",
GetAnonymStr(resolvedPath).c_str());
return INVALID_PARAMETERS_ERR;
}
int32_t (*ServiceCollaborationManagerExport)(ServiceCollaborationManager_API *exportapi) = nullptr;
dllHandle_ = dlopen(resolvedPath.c_str(), RTLD_LAZY);
if (dllHandle_ == nullptr) {
HILOGE("Open dms interactive adapter shared object fail, resolvedPath [%{public}s].", resolvedPath.c_str());
HILOGE("Open dms interactive adapter shared object fail, resolvedPath [%{public}s].",
GetAnonymStr(resolvedPath).c_str());
return NOT_FIND_SERVICE_REGISTRY;
}

View File

@ -173,7 +173,10 @@ int32_t SoftbusAdapter::RegisterSoftbusEventListener(const std::shared_ptr<Softb
HILOGE("Registering listener failed");
return SOFTBUS_INVALID_PARAM;
}
{
std::lock_guard<std::mutex> lock(softbusAdapterListenerMutex_);
softbusAdapterListener_ = listener;
}
EventListener eventListener;
eventListener.event = FOREGROUND_APP;
eventListener.freq = EVENT_MID_FREQ;
@ -195,7 +198,10 @@ int32_t SoftbusAdapter::UnregisterSoftbusEventListener(const std::shared_ptr<Sof
HILOGE("Unregistering listener failed");
return SOFTBUS_INVALID_PARAM;
}
{
std::lock_guard<std::mutex> lock(softbusAdapterListenerMutex_);
softbusAdapterListener_ = listener;
}
EventListener eventListener;
eventListener.event = FOREGROUND_APP;
eventListener.freq = EVENT_MID_FREQ;