From 78874c8b8b4b1c3318efcae074af7b2f6db0b482 Mon Sep 17 00:00:00 2001 From: zhangcui Date: Wed, 22 Mar 2023 08:01:37 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangcui --- device/base/src/common.cpp | 2 +- device/plugins/native_daemon/src/elf_file.cpp | 4 ++-- hiebpf/src/bpf_controller.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index ab7976987..f9a3488ff 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -324,7 +324,7 @@ bool CheckApplicationPermission(int pid, const std::string& processName) HILOG_ERROR(LOG_CORE, "Get process name by pid failed!"); return false; } - bundleName = bundleName.substr(0, strlen(bundleName.c_str())); + bundleName.resize(strlen(bundleName.c_str() + 1); // 1 is end '0/' } else { bundleName = processName; } diff --git a/device/plugins/native_daemon/src/elf_file.cpp b/device/plugins/native_daemon/src/elf_file.cpp index 91471f8e8..8982ff5b7 100644 --- a/device/plugins/native_daemon/src/elf_file.cpp +++ b/device/plugins/native_daemon/src/elf_file.cpp @@ -295,7 +295,7 @@ bool ElfFile::ParseSymNamesStr() const auto &shdr = shdrs_[secName]; uint64_t secOffset = shdr->fileOffset_; uint64_t secSize = shdr->secSize_; - int64_t ret = lseek(fd_, secOffset, SEEK_SET); + (void)lseek(fd_, secOffset, SEEK_SET); char *secBuf = new (std::nothrow) char[secSize]; if (secBuf == nullptr) { HLOGE("Error in ElfFile::ParsesymNamesStr(): new failed"); @@ -304,7 +304,7 @@ bool ElfFile::ParseSymNamesStr() if (memset_s(secBuf, secSize, '\0', secSize) != EOK) { HLOGE("memset failed"); } - ret = ReadFile(secBuf, secSize); + int64_t ret = ReadFile(secBuf, secSize); HLOG_ASSERT(ret == static_cast(secSize)); symNamesStr_ = std::string(secBuf, secSize); if (symNamesStr_ == "") { diff --git a/hiebpf/src/bpf_controller.cpp b/hiebpf/src/bpf_controller.cpp index 04e611599..e2dabdd28 100644 --- a/hiebpf/src/bpf_controller.cpp +++ b/hiebpf/src/bpf_controller.cpp @@ -794,7 +794,7 @@ int BPFController::DumpFSTraceEvent(BPFController *bpfctlr, void *data, size_t d << "\nips: " << cmplt_event.nips << "\nips:" << std::setw(16) << std::hex; - for (int i = 0; i < cmplt_event.nips; ++i) { + for (uint32_t i = 0; i < cmplt_event.nips; ++i) { std::cout << "\n " << cmplt_event.ips[i]; } std::cout << std::dec << std::endl; @@ -837,7 +837,7 @@ int BPFController::DumpPFTraceEvent(BPFController *bpfctlr, void *data, size_t d << "\ncomm: " << cmplt_event.comm << "\nips: " << cmplt_event.nips << std::setw(16) << std::hex; - for (int i = 0; i < cmplt_event.nips; ++i) { + for (uint32_t i = 0; i < cmplt_event.nips; ++i) { std::cout << "\n " << cmplt_event.ips[i]; } std::cout << std::dec << std::endl; @@ -881,7 +881,7 @@ int BPFController::DumpBIOTraceEvent(BPFController *bpfctlr, void *data, size_t << "\nblkcnt: " << cmplt_event.blkcnt << "\nips: " << cmplt_event.nips << std::setw(16) << std::hex; - for (int i = 0; i < cmplt_event.nips; ++i) { + for (uint32_t i = 0; i < cmplt_event.nips; ++i) { std::cout << "\n " << cmplt_event.ips[i]; } std::cout << std::dec << std::endl; From dbf7ed38df42b67bafb94859bd7d8eedb749374c Mon Sep 17 00:00:00 2001 From: zhangcui Date: Wed, 22 Mar 2023 08:01:51 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangcui --- device/plugins/ftrace_plugin/src/ftrace_parser.cpp | 2 +- device/plugins/ftrace_plugin/src/process_utils.cpp | 3 --- device/plugins/process_plugin/src/process_data_plugin.cpp | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/device/plugins/ftrace_plugin/src/ftrace_parser.cpp b/device/plugins/ftrace_plugin/src/ftrace_parser.cpp index 3ca3af8eb..55063edbd 100644 --- a/device/plugins/ftrace_plugin/src/ftrace_parser.cpp +++ b/device/plugins/ftrace_plugin/src/ftrace_parser.cpp @@ -58,7 +58,7 @@ inline uint64_t GetTimestampIncrements(uint64_t ext) return ext << TS_EXT_SHIFT; } -bool ReadInc(uint8_t* start[], uint8_t end[], void* outData, size_t outSize) +bool ReadInc(uint8_t* start[], const uint8_t end[], void* outData, size_t outSize) { if ((end - *start) < static_cast(outSize)) { return false; diff --git a/device/plugins/ftrace_plugin/src/process_utils.cpp b/device/plugins/ftrace_plugin/src/process_utils.cpp index 5dbe4ec70..691338015 100644 --- a/device/plugins/ftrace_plugin/src/process_utils.cpp +++ b/device/plugins/ftrace_plugin/src/process_utils.cpp @@ -136,21 +136,18 @@ static bool ExecuteProcess(const std::string& bin, int errFd = nullFd; CHECK_TRUE(inFd >= 0, false, "open /dev/null failed, %d", errno); CHECK_TRUE(dup2(inFd, STDIN_FILENO) != -1, false, "dup nullFD to stdin failed, %d", errno); - inFd = INVALID_FD; // for static check warning // redirect outFd to stdout if (out2pipe) { outFd = pipeFd; } CHECK_TRUE(dup2(outFd, STDOUT_FILENO) != -1, false, "dup fd %d to stdout failed, %d", outFd, errno); - outFd = INVALID_FD; // for static check warning // redirect errFd to stderr if (err2pipe) { errFd = pipeFd; } CHECK_TRUE(dup2(errFd, STDERR_FILENO) != -1, false, "dup fd %d to stderr failed, %d", errFd, errno); - errFd = INVALID_FD; // for static check warning CHECK_TRUE(close(nullFd) != -1, false, "close nullFd failed, %d", errno); CHECK_TRUE(close(pipeFd) != -1, false, "close pipeFd failed, %d", errno); diff --git a/device/plugins/process_plugin/src/process_data_plugin.cpp b/device/plugins/process_plugin/src/process_data_plugin.cpp index d719e4ab3..551ffeca1 100644 --- a/device/plugins/process_plugin/src/process_data_plugin.cpp +++ b/device/plugins/process_plugin/src/process_data_plugin.cpp @@ -582,7 +582,7 @@ bool ProcessDataPlugin::WritePssData(int pid, PssInfo* protoc) getline(input, line); line += '\n'; std::string::size_type pos = 0u; - if ((pos = line.find("Pss:", pos)) != std::string::npos) { + if (line.find("Pss:", pos) != std::string::npos) { char* pTmp = const_cast(line.c_str()); uint64_t num; CHECK_TRUE(GetValidValue(pTmp, num), false, "%s: FindFirstNum failed", __func__); From 138621b9ecde34b9aa852733712806eb29aee60e Mon Sep 17 00:00:00 2001 From: zhangcui Date: Wed, 22 Mar 2023 08:44:58 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangcui --- device/base/src/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index f9a3488ff..683fab7ff 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -324,7 +324,7 @@ bool CheckApplicationPermission(int pid, const std::string& processName) HILOG_ERROR(LOG_CORE, "Get process name by pid failed!"); return false; } - bundleName.resize(strlen(bundleName.c_str() + 1); // 1 is end '0/' + bundleName.resize(strlen(bundleName.c_str()); } else { bundleName = processName; } From 101b780fbc9dbba99c09400c3e908368f3d11f8d Mon Sep 17 00:00:00 2001 From: zhangcui Date: Wed, 22 Mar 2023 09:05:26 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangcui --- device/base/src/common.cpp | 2 +- device/plugins/ftrace_plugin/src/process_utils.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/device/base/src/common.cpp b/device/base/src/common.cpp index 683fab7ff..45e3233d3 100644 --- a/device/base/src/common.cpp +++ b/device/base/src/common.cpp @@ -324,7 +324,7 @@ bool CheckApplicationPermission(int pid, const std::string& processName) HILOG_ERROR(LOG_CORE, "Get process name by pid failed!"); return false; } - bundleName.resize(strlen(bundleName.c_str()); + bundleName.resize(strlen(bundleName.c_str())); } else { bundleName = processName; } diff --git a/device/plugins/ftrace_plugin/src/process_utils.cpp b/device/plugins/ftrace_plugin/src/process_utils.cpp index 691338015..2aa53a6fa 100644 --- a/device/plugins/ftrace_plugin/src/process_utils.cpp +++ b/device/plugins/ftrace_plugin/src/process_utils.cpp @@ -29,7 +29,6 @@ namespace { constexpr int RD = 0; constexpr int WR = 1; -constexpr int INVALID_FD = -1; } // namespace struct PipedSigHandler { From 25213ef86204268e11e4d2022871dc875ee3a2bb Mon Sep 17 00:00:00 2001 From: zhangcui Date: Thu, 23 Mar 2023 02:20:23 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangcui --- device/plugins/native_hook/test/hook_test.c | 2 +- device/plugins/native_hook/test/malloc_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/device/plugins/native_hook/test/hook_test.c b/device/plugins/native_hook/test/hook_test.c index fc334b116..6739ff302 100644 --- a/device/plugins/native_hook/test/hook_test.c +++ b/device/plugins/native_hook/test/hook_test.c @@ -238,7 +238,7 @@ void* ThreadFuncC(void* param) // 打开文件到内存中 int OpenFile(const char* fileName) { - int fd = open(fileName, O_RDWR | O_CREAT, (mode_t)0777); + int fd = open(fileName, O_RDWR | O_CREAT, (mode_t)0644); // 0644 rw-r--r-- if (fd == -1) { printf("can not open the file\n"); return -1; diff --git a/device/plugins/native_hook/test/malloc_test.cpp b/device/plugins/native_hook/test/malloc_test.cpp index 693664e33..3dd151d63 100755 --- a/device/plugins/native_hook/test/malloc_test.cpp +++ b/device/plugins/native_hook/test/malloc_test.cpp @@ -256,7 +256,7 @@ static void* ThreadFuncC(void* param) // 打开文件到内存中 static int OpenFile(const char* fileName) { - int fd = open(fileName, O_RDWR | O_CREAT, (mode_t)0777); + int fd = open(fileName, O_RDWR | O_CREAT, (mode_t)0644); // 0644 rw-r--r-- if (fd == -1) { printf("can not open the file\n"); return -1;