mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
!9423 [Bug]: CJEnv安全告警清零
Merge pull request !9423 from liubinyu/fix_codecheck
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "cj_environment.h"
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
#include "cj_hilog.h"
|
||||
@@ -476,13 +475,6 @@ bool CJEnvironment::StartDebugger()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsCJAbility(const std::string& info)
|
||||
{
|
||||
// in cj application, the srcEntry format should be packageName.AbilityClassName.
|
||||
std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$";
|
||||
return std::regex_match(info, std::regex(pattern));
|
||||
}
|
||||
|
||||
CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance()
|
||||
{
|
||||
static CJEnvMethods gCJEnvMethods {
|
||||
@@ -522,9 +514,6 @@ CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance()
|
||||
.registerCJUncaughtExceptionHandler = [](const CJUncaughtExceptionInfo& handle) {
|
||||
return CJEnvironment::GetInstance()->RegisterCJUncaughtExceptionHandler(handle);
|
||||
},
|
||||
.isCJAbility = [](const std::string& info) {
|
||||
return IsCJAbility(info);
|
||||
},
|
||||
.setSanitizerKindRuntimeVersion = [](SanitizerKind kind) {
|
||||
return CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(kind);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,6 @@ private:
|
||||
SanitizerKind sanitizerKind_ {SanitizerKind::NONE};
|
||||
};
|
||||
|
||||
CJ_EXPORT bool IsCJAbility(const std::string& info);
|
||||
}
|
||||
|
||||
#endif //OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
|
||||
|
||||
@@ -50,7 +50,6 @@ struct CJEnvMethods {
|
||||
void* (*loadCJLibrary)(const char* dllName) = nullptr;
|
||||
bool (*startDebugger)() = nullptr;
|
||||
void (*registerCJUncaughtExceptionHandler)(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) = nullptr;
|
||||
bool (*isCJAbility)(const std::string& info) = nullptr;
|
||||
void (*setSanitizerKindRuntimeVersion)(SanitizerKind kind) = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
|
||||
#include "cj_envsetup.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
@@ -77,10 +78,15 @@ void CJRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths)
|
||||
appPath += appPath.empty() ? libPath : ":" + libPath;
|
||||
}
|
||||
}
|
||||
OHOS::CJEnv::LoadInstance()->initCJChipSDKNS(CJ_CHIPSDK_PATH);
|
||||
OHOS::CJEnv::LoadInstance()->initCJAppNS(appPath);
|
||||
OHOS::CJEnv::LoadInstance()->initCJSDKNS(CJ_RT_PATH + ":" + CJ_LIB_PATH);
|
||||
OHOS::CJEnv::LoadInstance()->initCJSysNS(CJ_SYSLIB_PATH);
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return;
|
||||
}
|
||||
cjEnv->initCJChipSDKNS(CJ_CHIPSDK_PATH);
|
||||
cjEnv->initCJAppNS(appPath);
|
||||
cjEnv->initCJSDKNS(CJ_RT_PATH + ":" + CJ_LIB_PATH);
|
||||
cjEnv->initCJSysNS(CJ_SYSLIB_PATH);
|
||||
}
|
||||
|
||||
bool CJRuntime::Initialize(const Options& options)
|
||||
@@ -89,11 +95,16 @@ bool CJRuntime::Initialize(const Options& options)
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJRuntime Initialize fail, language mismatch");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::CJEnv::LoadInstance()->startRuntime()) {
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return false;
|
||||
}
|
||||
if (!cjEnv->startRuntime()) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "start cj runtime failed");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::CJEnv::LoadInstance()->startUIScheduler()) {
|
||||
if (!cjEnv->startUIScheduler()) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "start cj ui context failed");
|
||||
return false;
|
||||
}
|
||||
@@ -108,16 +119,28 @@ bool CJRuntime::Initialize(const Options& options)
|
||||
|
||||
void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo)
|
||||
{
|
||||
OHOS::CJEnv::LoadInstance()->registerCJUncaughtExceptionHandler(uncaughtExceptionInfo);
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return;
|
||||
}
|
||||
cjEnv->registerCJUncaughtExceptionHandler(uncaughtExceptionInfo);
|
||||
}
|
||||
|
||||
bool CJRuntime::IsCJAbility(const std::string& info)
|
||||
{
|
||||
return OHOS::CJEnv::LoadInstance()->isCJAbility(info);
|
||||
// in cj application, the srcEntry format should be packageName.AbilityClassName.
|
||||
std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$";
|
||||
return std::regex_match(info, std::regex(pattern));
|
||||
}
|
||||
|
||||
bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
{
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return false;
|
||||
}
|
||||
void* handle = nullptr;
|
||||
for (const auto& libPath : appLibPaths) {
|
||||
for (auto& itor : std::filesystem::directory_iterator(libPath)) {
|
||||
@@ -125,7 +148,7 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
if (itor.path().string().find("ohos_app_cangjie") == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
handle = OHOS::CJEnv::LoadInstance()->loadCJLibrary(itor.path().c_str());
|
||||
handle = cjEnv->loadCJLibrary(itor.path().c_str());
|
||||
if (handle == nullptr) {
|
||||
char* errMsg = dlerror();
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME,
|
||||
@@ -140,17 +163,32 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
|
||||
void CJRuntime::SetAsanVersion()
|
||||
{
|
||||
OHOS::CJEnv::LoadInstance()->setSanitizerKindRuntimeVersion(SanitizerKind::ASAN);
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return;
|
||||
}
|
||||
cjEnv->setSanitizerKindRuntimeVersion(SanitizerKind::ASAN);
|
||||
}
|
||||
|
||||
void CJRuntime::SetTsanVersion()
|
||||
{
|
||||
OHOS::CJEnv::LoadInstance()->setSanitizerKindRuntimeVersion(SanitizerKind::TSAN);
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return;
|
||||
}
|
||||
cjEnv->setSanitizerKindRuntimeVersion(SanitizerKind::TSAN);
|
||||
}
|
||||
|
||||
void CJRuntime::SetHWAsanVersion()
|
||||
{
|
||||
OHOS::CJEnv::LoadInstance()->setSanitizerKindRuntimeVersion(SanitizerKind::HWASAN);
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return;
|
||||
}
|
||||
cjEnv->setSanitizerKindRuntimeVersion(SanitizerKind::HWASAN);
|
||||
}
|
||||
|
||||
void CJRuntime::StartDebugMode(const DebugOption dOption)
|
||||
@@ -192,7 +230,12 @@ void CJRuntime::StartDebugMode(const DebugOption dOption)
|
||||
|
||||
bool CJRuntime::StartDebugger()
|
||||
{
|
||||
return OHOS::CJEnv::LoadInstance()->startDebugger();
|
||||
auto cjEnv = OHOS::CJEnv::LoadInstance();
|
||||
if (cjEnv == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CJRUNTIME, "CJEnv LoadInstance failed.");
|
||||
return false;
|
||||
}
|
||||
return cjEnv->startDebugger();
|
||||
}
|
||||
|
||||
void CJRuntime::UnLoadCJAppLibrary()
|
||||
|
||||
Reference in New Issue
Block a user