mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2025-02-25 14:53:32 +00:00
Modify code security specification alarm
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAGCUP?from=project-issue Signed-off-by: yy <yejunwen2@h-partners.com>
This commit is contained in:
parent
1acae53762
commit
a210c6711f
@ -91,7 +91,7 @@ struct CallThisArgvWithReturnArgs {
|
||||
struct JSCallArgs {
|
||||
JSCallArgs() {}
|
||||
JSCallArgs(JSCallMode m) : mode(m) {}
|
||||
JSCallMode mode;
|
||||
JSCallMode mode {JSCallMode::CALL_ARG0};
|
||||
union {
|
||||
CallArgs callArgs;
|
||||
CallArgsWithThis callArgsWithThis;
|
||||
@ -152,7 +152,7 @@ private:
|
||||
|
||||
bool isFast_ {true};
|
||||
bool isBridge_ {false};
|
||||
bool isForBaseline_;
|
||||
bool isForBaseline_ {false};
|
||||
GateRef sp_ {0};
|
||||
GateRef method_ {0};
|
||||
GateRef numArgs_ {0};
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fileMutex_);
|
||||
static char soBuildId[NAME_MAX] = { '\0' };
|
||||
if (!GetRuntimeBuildId(soBuildId) || IsCharEmpty(soBuildId)) {
|
||||
if (!GetRuntimeBuildId(soBuildId, NAME_MAX) || IsCharEmpty(soBuildId)) {
|
||||
LOG_ECMA(INFO) << "can't get so buildId.";
|
||||
return;
|
||||
}
|
||||
@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
GetRuntimeInfoByPath(lines, realOutPath.c_str(), soBuildId);
|
||||
static char timestamp[TIME_STAMP_SIZE] = { '\0' };
|
||||
if (!GetMicrosecondsTimeStamp(timestamp)) {
|
||||
if (!GetMicrosecondsTimeStamp(timestamp, TIME_STAMP_SIZE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fileMutex_);
|
||||
static char soBuildId[NAME_MAX] = { '\0' };
|
||||
if (!GetRuntimeBuildId(soBuildId) || IsCharEmpty(soBuildId)) {
|
||||
if (!GetRuntimeBuildId(soBuildId, NAME_MAX) || IsCharEmpty(soBuildId)) {
|
||||
return;
|
||||
}
|
||||
static char lines[MAX_LENGTH][BUFFER_SIZE];
|
||||
@ -113,7 +113,7 @@ public:
|
||||
}
|
||||
GetCrashRuntimeInfoList(lines);
|
||||
static char timestamp[TIME_STAMP_SIZE] = { '\0' };
|
||||
if (!GetMicrosecondsTimeStamp(timestamp)) {
|
||||
if (!GetMicrosecondsTimeStamp(timestamp, TIME_STAMP_SIZE)) {
|
||||
return;
|
||||
}
|
||||
int lineCount = getLength(lines, MAX_LENGTH);
|
||||
@ -123,7 +123,7 @@ public:
|
||||
}
|
||||
}
|
||||
static char realOutPath[PATH_MAX] = { '\0' };
|
||||
if (!GetCrashSandBoxRealPath(realOutPath) || IsCharEmpty(realOutPath)) {
|
||||
if (!GetCrashSandBoxRealPath(realOutPath, PATH_MAX) || IsCharEmpty(realOutPath)) {
|
||||
return;
|
||||
}
|
||||
SetRuntimeInfo(realOutPath, lines);
|
||||
@ -199,7 +199,7 @@ public:
|
||||
return RuntimeInfoType::NONE;
|
||||
}
|
||||
|
||||
virtual bool GetRuntimeBuildId(char *buildId) const
|
||||
virtual bool GetRuntimeBuildId(char *buildId, int length) const
|
||||
{
|
||||
if (!FileExist(OhosConstants::RUNTIME_SO_PATH)) {
|
||||
return false;
|
||||
@ -215,13 +215,13 @@ public:
|
||||
if (fileMap.GetOriginAddr() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ParseELFSectionsForBuildId(fileMap, buildId);
|
||||
ParseELFSectionsForBuildId(fileMap, buildId, length);
|
||||
ecmascript::FileUnMap(fileMap);
|
||||
fileMap.Reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GetMicrosecondsTimeStamp(char *timestamp) const
|
||||
virtual bool GetMicrosecondsTimeStamp(char *timestamp, size_t length) const
|
||||
{
|
||||
time_t current_time;
|
||||
if (time(¤t_time) == -1) {
|
||||
@ -231,16 +231,16 @@ public:
|
||||
if (local_time == NULL) {
|
||||
return false;
|
||||
}
|
||||
int result = strftime(timestamp, TIME_STAMP_SIZE, "%Y-%m-%d %H:%M:%S", local_time);
|
||||
size_t result = strftime(timestamp, length, "%Y-%m-%d %H:%M:%S", local_time);
|
||||
if (result == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GetCrashSandBoxRealPath(char *realOutPath) const
|
||||
virtual bool GetCrashSandBoxRealPath(char *realOutPath, size_t length) const
|
||||
{
|
||||
if (!ecmascript::RealPathByChar(OhosConstants::SANDBOX_ARK_PROFILE_PATH, realOutPath, PATH_MAX, false)) {
|
||||
if (!ecmascript::RealPathByChar(OhosConstants::SANDBOX_ARK_PROFILE_PATH, realOutPath, length, false)) {
|
||||
return false;
|
||||
}
|
||||
if (strcat_s(realOutPath, NAME_MAX, OhosConstants::PATH_SEPARATOR) != 0) {
|
||||
@ -311,14 +311,14 @@ protected:
|
||||
void GetCrashRuntimeInfoList(char lines[][BUFFER_SIZE]) const
|
||||
{
|
||||
static char realOutPath[PATH_MAX] = { '\0' };
|
||||
if (!GetCrashSandBoxRealPath(realOutPath)) {
|
||||
if (!GetCrashSandBoxRealPath(realOutPath, PATH_MAX)) {
|
||||
return;
|
||||
}
|
||||
if (!FileExist(realOutPath)) {
|
||||
return;
|
||||
}
|
||||
static char soBuildId[NAME_MAX] = { '\0' };
|
||||
if (!GetRuntimeBuildId(soBuildId)) {
|
||||
if (!GetRuntimeBuildId(soBuildId, NAME_MAX)) {
|
||||
return;
|
||||
}
|
||||
if (IsCharEmpty(soBuildId)) {
|
||||
@ -338,7 +338,7 @@ protected:
|
||||
return;
|
||||
}
|
||||
char soBuildId[NAME_MAX] = { '\0' };
|
||||
if (!GetRuntimeBuildId(soBuildId)) {
|
||||
if (!GetRuntimeBuildId(soBuildId, NAME_MAX)) {
|
||||
return;
|
||||
}
|
||||
if (IsCharEmpty(soBuildId)) {
|
||||
@ -387,7 +387,7 @@ protected:
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void ParseELFSectionsForBuildId(ecmascript::MemMap &fileMap, char *buildId) const
|
||||
void ParseELFSectionsForBuildId(ecmascript::MemMap &fileMap, char *buildId, int length) const
|
||||
{
|
||||
llvm::ELF::Elf64_Ehdr *ehdr = reinterpret_cast<llvm::ELF::Elf64_Ehdr *>(fileMap.GetOriginAddr());
|
||||
char *addr = reinterpret_cast<char *>(ehdr);
|
||||
@ -426,10 +426,10 @@ protected:
|
||||
|
||||
char *curShNameValueForNhdr = reinterpret_cast<char *>(addr + buildIdOffset + sizeof(*nhdr) +
|
||||
AlignValues(nhdr->n_namesz, 4));
|
||||
GetReadableBuildId(curShNameValueForNhdr, buildId);
|
||||
GetReadableBuildId(curShNameValueForNhdr, buildId, length);
|
||||
}
|
||||
|
||||
void GetReadableBuildId(char *buildIdHex, char *buildId) const
|
||||
void GetReadableBuildId(char *buildIdHex, char *buildId, int length) const
|
||||
{
|
||||
if (IsCharEmpty(buildIdHex)) {
|
||||
return;
|
||||
@ -440,9 +440,13 @@ protected:
|
||||
const int len = strlen(buildIdHex);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
int lowHexExpand = i * HEX_EXPAND_PARAM + 1;
|
||||
if (lowHexExpand >= length) {
|
||||
break;
|
||||
}
|
||||
unsigned int n = buildIdHex[i];
|
||||
buildId[i * HEX_EXPAND_PARAM] = HEXTABLE[(n >> 4) % HEXLENGTH]; // 4 : higher 4 bit of uint8
|
||||
buildId[i * HEX_EXPAND_PARAM + 1] = HEXTABLE[n % HEXLENGTH];
|
||||
buildId[lowHexExpand - 1] = HEXTABLE[(n >> 4) % HEXLENGTH]; // 4 : higher 4 bit of uint8
|
||||
buildId[lowHexExpand] = HEXTABLE[n % HEXLENGTH];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ HWTEST_F_L0(CrashTest, CrashGetBuildId)
|
||||
{
|
||||
char soBuildId[NAME_MAX];
|
||||
ohos::AotRuntimeInfo *runtimeInfo = new MockAotRuntimeInfo();
|
||||
runtimeInfo->GetRuntimeBuildId(soBuildId);
|
||||
runtimeInfo->GetRuntimeBuildId(soBuildId, NAME_MAX);
|
||||
ASSERT_TRUE(std::string(soBuildId).size() > 0);
|
||||
ASSERT_EQ(std::string(soBuildId), "abcd1234567890");
|
||||
}
|
||||
@ -66,7 +66,7 @@ HWTEST_F_L0(CrashTest, GetMicrosecondsTimeStamp)
|
||||
{
|
||||
char timestamp[ohos::AotRuntimeInfo::TIME_STAMP_SIZE];
|
||||
ohos::AotRuntimeInfo *runtimeInfo = new MockAotRuntimeInfo();
|
||||
runtimeInfo->GetMicrosecondsTimeStamp(timestamp);
|
||||
runtimeInfo->GetMicrosecondsTimeStamp(timestamp, ohos::AotRuntimeInfo::TIME_STAMP_SIZE);
|
||||
ASSERT_TRUE(std::string(timestamp).size() > 0);
|
||||
ASSERT_EQ(std::string(timestamp), "1970-01-01 00:00:00");
|
||||
}
|
||||
@ -76,13 +76,13 @@ HWTEST_F_L0(CrashTest, BuildCrashRuntimeInfo)
|
||||
char timestamp[ohos::AotRuntimeInfo::TIME_STAMP_SIZE];
|
||||
char soBuildId[NAME_MAX];
|
||||
ohos::AotRuntimeInfo *runtimeInfo = new MockAotRuntimeInfo();
|
||||
runtimeInfo->GetMicrosecondsTimeStamp(timestamp);
|
||||
runtimeInfo->GetRuntimeBuildId(soBuildId);
|
||||
runtimeInfo->GetMicrosecondsTimeStamp(timestamp, ohos::AotRuntimeInfo::TIME_STAMP_SIZE);
|
||||
runtimeInfo->GetRuntimeBuildId(soBuildId, NAME_MAX);
|
||||
char sanboxRealPath[PATH_MAX];
|
||||
mkdir(MockAotRuntimeInfo::SANBOX_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
std::ofstream file(sanboxRealPath);
|
||||
file.close();
|
||||
runtimeInfo->GetCrashSandBoxRealPath(sanboxRealPath);
|
||||
runtimeInfo->GetCrashSandBoxRealPath(sanboxRealPath, NAME_MAX);
|
||||
|
||||
runtimeInfo->BuildCrashRuntimeInfo(ecmascript::ohos::RuntimeInfoType::AOT_CRASH);
|
||||
runtimeInfo->BuildCrashRuntimeInfo(ecmascript::ohos::RuntimeInfoType::AOT_CRASH);
|
||||
@ -107,13 +107,13 @@ HWTEST_F_L0(CrashTest, BuildCompileRuntimeInfo)
|
||||
char timestamp[ohos::AotRuntimeInfo::TIME_STAMP_SIZE];
|
||||
char soBuildId[NAME_MAX];
|
||||
ohos::AotRuntimeInfo *runtimeInfo = new MockAotRuntimeInfo();
|
||||
runtimeInfo->GetMicrosecondsTimeStamp(timestamp);
|
||||
runtimeInfo->GetRuntimeBuildId(soBuildId);
|
||||
runtimeInfo->GetMicrosecondsTimeStamp(timestamp, ohos::AotRuntimeInfo::TIME_STAMP_SIZE);
|
||||
runtimeInfo->GetRuntimeBuildId(soBuildId, NAME_MAX);
|
||||
char sanboxRealPath[PATH_MAX];
|
||||
mkdir(MockAotRuntimeInfo::SANBOX_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
std::ofstream file(sanboxRealPath);
|
||||
file.close();
|
||||
runtimeInfo->GetCrashSandBoxRealPath(sanboxRealPath);
|
||||
runtimeInfo->GetCrashSandBoxRealPath(sanboxRealPath, NAME_MAX);
|
||||
|
||||
runtimeInfo->BuildCompileRuntimeInfo(ecmascript::ohos::RuntimeInfoType::AOT_CRASH, sanboxRealPath);
|
||||
runtimeInfo->BuildCompileRuntimeInfo(ecmascript::ohos::RuntimeInfoType::AOT_CRASH, sanboxRealPath);
|
||||
|
@ -20,33 +20,33 @@ MockAotRuntimeInfo::MockAotRuntimeInfo()
|
||||
{}
|
||||
MockAotRuntimeInfo::~MockAotRuntimeInfo()
|
||||
{}
|
||||
bool MockAotRuntimeInfo::GetRuntimeBuildId(char *buildId) const
|
||||
bool MockAotRuntimeInfo::GetRuntimeBuildId(char *buildId, int length) const
|
||||
{
|
||||
char tmp[NAME_MAX] = "abcd1234567890";
|
||||
if (strcpy_s(buildId, NAME_MAX, tmp) != 0) {
|
||||
if (strcpy_s(buildId, length, tmp) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MockAotRuntimeInfo::GetMicrosecondsTimeStamp(char *timestamp) const
|
||||
bool MockAotRuntimeInfo::GetMicrosecondsTimeStamp(char *timestamp, size_t length) const
|
||||
{
|
||||
char tmp[ecmascript::ohos::AotRuntimeInfo::TIME_STAMP_SIZE] = "1970-01-01 00:00:00";
|
||||
if (strcpy_s(timestamp, ecmascript::ohos::AotRuntimeInfo::TIME_STAMP_SIZE, tmp) != 0) {
|
||||
if (strcpy_s(timestamp, length, tmp) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MockAotRuntimeInfo::GetCrashSandBoxRealPath(char *realOutPath) const
|
||||
bool MockAotRuntimeInfo::GetCrashSandBoxRealPath(char *realOutPath, size_t length) const
|
||||
{
|
||||
if (strcpy_s(realOutPath, NAME_MAX, SANBOX_DIR) != 0) {
|
||||
if (strcpy_s(realOutPath, length, SANBOX_DIR) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (strcat_s(realOutPath, NAME_MAX, "/") != 0) {
|
||||
if (strcat_s(realOutPath, length, "/") != 0) {
|
||||
return false;
|
||||
}
|
||||
if (strcat_s(realOutPath, NAME_MAX, AOT_RUNTIME_INFO) != 0) {
|
||||
if (strcat_s(realOutPath, length, AOT_RUNTIME_INFO) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -27,9 +27,9 @@ public:
|
||||
MockAotRuntimeInfo();
|
||||
~MockAotRuntimeInfo();
|
||||
|
||||
bool GetRuntimeBuildId(char *buildId) const override;
|
||||
bool GetMicrosecondsTimeStamp(char *timestamp) const override;
|
||||
bool GetCrashSandBoxRealPath(char *realOutPath) const override;
|
||||
bool GetRuntimeBuildId(char *buildId, int length) const override;
|
||||
bool GetMicrosecondsTimeStamp(char *timestamp, size_t length) const override;
|
||||
bool GetCrashSandBoxRealPath(char *realOutPath, size_t length) const override;
|
||||
|
||||
bool BuildRuntimeInfoPart(char *runtimeInfoPart, const char *soBuildId, const char *timestamp,
|
||||
ecmascript::ohos::RuntimeInfoType type) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user