diff --git a/interfaces/innerkits/native/src/hiperf_client.cpp b/interfaces/innerkits/native/src/hiperf_client.cpp index a946985b2ee8c53c047693c172a2352450cda379..cc263d40419b7ee1ee001caf5dfcdc387e60b7d5 100644 --- a/interfaces/innerkits/native/src/hiperf_client.cpp +++ b/interfaces/innerkits/native/src/hiperf_client.cpp @@ -341,26 +341,14 @@ Client::Client(const std::string &outputDir) bool Client::Setup(std::string outputDir) { - std::string CurrentCommandPath = CURRENT_PATH + HIPERF_COMMAND_NAME; std::string SystemCommandPath = SYSTEM_BIN_PATH + HIPERF_COMMAND_NAME; - std::string TempCommandPath = TempBinPath + HIPERF_COMMAND_NAME; if (!outputDir.empty() && outputDir.back() != '/') { outputDir.push_back('/'); } HIPERF_HILOGI(MODULE_CPP_API, "outputDir setup to %" HILOG_PUBLIC "s\n", outputDir.c_str()); - // found command path - if (access(SystemCommandPath.c_str(), X_OK) == 0) { - executeCommandPath_ = SystemCommandPath; - } else if (access(TempCommandPath.c_str(), X_OK) == 0) { - executeCommandPath_ = TempCommandPath; - } else if (access(CurrentCommandPath.c_str(), X_OK) == 0) { - executeCommandPath_ = CurrentCommandPath; - } else { - HIPERF_HILOGI(MODULE_CPP_API, "no hiperf command found\n"); - return ready_; - } + executeCommandPath_ = SystemCommandPath; // check output path // found command path diff --git a/src/perf_events.cpp b/src/perf_events.cpp index 39ca41b9f9ed9478f1d26d060ac0ca1ec2003bd6..8bfb96450e792ed20157a309e76ae4acc70c4e4d 100644 --- a/src/perf_events.cpp +++ b/src/perf_events.cpp @@ -617,6 +617,7 @@ bool PerfEvents::PrepareRecordThread() recordBuf_ = std::make_unique(CalcBufferSize()); } catch (const std::exception &e) { printf("create record buffer(size %zu) failed: %s\n", CalcBufferSize(), e.what()); + HIPERF_HILOGI(MODULE_DEFAULT, "create record buffer failed: %{public}s", e.what()); return false; } readRecordThreadRunning_ = true; diff --git a/src/perf_file_reader.cpp b/src/perf_file_reader.cpp index 34fa4a595e5d00b1ec6e47422364f59464184f16..317a27dfd0ae8920e4b3414fdce1084be0cccb90 100644 --- a/src/perf_file_reader.cpp +++ b/src/perf_file_reader.cpp @@ -267,7 +267,7 @@ bool PerfFileReader::ReadRecord(ProcessRecordCB &callback) if (header == nullptr) { HLOGE("read record header is null"); return false; - } else if (header->size > RECORD_SIZE_LIMIT) { + } else if (header->size > RECORD_SIZE_LIMIT || header->size < sizeof(perf_event_header)) { HLOGE("read record header size error %hu", header->size); return false; } diff --git a/src/perf_file_writer.cpp b/src/perf_file_writer.cpp index 4ee08e00bee7a9728042c8929e33fbb0c8852972..1573d47d446b440512888d3a0deeb7bb13f996c2 100644 --- a/src/perf_file_writer.cpp +++ b/src/perf_file_writer.cpp @@ -171,7 +171,10 @@ bool PerfFileWriter::ReadRecords(ProcessRecordCB &callback) return false; } else { perf_event_header *header = reinterpret_cast(buf); - HLOG_ASSERT(header->size < RECORD_SIZE_LIMIT); + if (header->size > RECORD_SIZE_LIMIT || header->size < sizeof(perf_event_header)) { + HLOGE("read record header size error %hu", header->size); + return false; + } if (remainingSize >= header->size) { size_t headerSize = sizeof(perf_event_header); if (Read(buf + headerSize, header->size - headerSize)) {