diff --git a/include/pcerrc.h b/include/pcerrc.h index b2a1fdf6cb443a63d74b9cce65565d58c93070da..ff666eaa7f0e9594094fb3d0cb87fb3fc646fb88 100644 --- a/include/pcerrc.h +++ b/include/pcerrc.h @@ -125,6 +125,7 @@ extern "C" { #define LIBPERF_ERR_COUNTER_INDEX_IS_ZERO 1078 #define LIBPERF_ERR_BPF_ACT_FAILED 1079 #define LIBPERF_ERR_INVALID_BPF_PARAM 1080 +#define LIBPERF_ERR_NULL_POINTER 1081 #define UNKNOWN_ERROR 9999 diff --git a/pmu/dump_perf_data.cpp b/pmu/dump_perf_data.cpp index c17937b3cb21695069be47366a2765f36366a748..fe307b06c36134ed35b8b9e20251606219e0161c 100644 --- a/pmu/dump_perf_data.cpp +++ b/pmu/dump_perf_data.cpp @@ -636,6 +636,11 @@ map> dumpers; PmuFile PmuBeginWrite(const char *path, const PmuAttr *pattr, const int addIdHdr) { + if (pattr == nullptr) { + New(LIBPERF_ERR_NULL_POINTER, "PmuAttr cannot be null"); + return NULL; + } + try { unique_ptr dumper(new PerfDataDumper(path, addIdHdr)); int err = dumper->Start(pattr); diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index 6e2f1c7086b2b4bbac2d4f5d6a0bfa9d490c995b..b83c4afa4c0704d1ef6134ab6f84ff86106eeea7 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -545,6 +545,10 @@ int PmuOpen(enum PmuTaskType collectType, struct PmuAttr *attr) { SetWarn(SUCCESS); New(SUCCESS); + if (attr == nullptr) { + New(LIBPERF_ERR_NULL_POINTER, "PmuAttr cannot be null"); + return -1; + } PmuAttr copiedAttr = *attr; pair previousEventList = {0, nullptr}; try { @@ -1112,12 +1116,19 @@ static void DumpStack(ofstream &out, Stack *stack, int dumpDwf) int PmuDumpData(struct PmuData *pmuData, unsigned len, char *filepath, int dumpDwf) { SetWarn(SUCCESS); + if (filepath == nullptr) { + New(LIBPERF_ERR_NULL_POINTER, "filepath cannot be null"); + return -1; + } ofstream out(filepath, ios_base::app); if (!out.is_open()) { New(LIBPERF_ERR_PATH_INACCESSIBLE, "cannot access: " + string(filepath)); return -1; } - + if (pmuData == nullptr) { + New(LIBPERF_ERR_NULL_POINTER, "PmuData cannot be null"); + return -1; + } for (unsigned i = 0; i < len; ++i) { auto &data = pmuData[i]; if (data.comm) { diff --git a/pmu/pmu_trace_analysis.cpp b/pmu/pmu_trace_analysis.cpp index 0411f682869ec0786251a2bbd17b4996595839a8..2f1df1f78480cf387a56d1406f409d91ca91daf6 100644 --- a/pmu/pmu_trace_analysis.cpp +++ b/pmu/pmu_trace_analysis.cpp @@ -184,6 +184,10 @@ int PmuTraceOpen(enum PmuTraceType traceType, struct PmuTraceAttr *traceAttr) return -1; #else SetWarn(SUCCESS); + if (traceAttr == nullptr) { + New(LIBPERF_ERR_NULL_POINTER, "PmuTraceAttr cannot be null"); + return -1; + } auto err = CheckTraceAttr(traceType, traceAttr); if (err != SUCCESS) { return -1; diff --git a/python/modules/kperf/perror.py b/python/modules/kperf/perror.py index 304f5483b4251e5d3b1a247902d861cb8ed56a2a..62cb6017da77bb0009d6df7705172186dd6297f6 100644 --- a/python/modules/kperf/perror.py +++ b/python/modules/kperf/perror.py @@ -124,6 +124,7 @@ class Error: LIBPERF_ERR_COUNTER_INDEX_IS_ZERO = 1078 LIBPERF_ERR_BPF_ACT_FAILED = 1079 LIBPERF_ERR_INVALID_BPF_PARAM = 1080 + LIBPERF_ERR_NULL_POINTER = 1081 UNKNOWN_ERROR = 9999 diff --git a/util/pcerr.cpp b/util/pcerr.cpp index 6d9c53c38e2399019ade1875758bb64991863a3e..9cf3f649aaba20f6da91135a6f65099783dca739 100644 --- a/util/pcerr.cpp +++ b/util/pcerr.cpp @@ -66,7 +66,8 @@ namespace pcerr { {LIBPERF_ERR_ALLOCATE_REGISTER_FAILED, "Allocate register failed!"}, {LIBPERF_ERR_CHECK_USER_ACCESS, "Check user access failed!"}, {LIBPERF_ERR_INVALID_BPF_PARAM, "check bpf mode failed"}, - {LIBPERF_ERR_BPF_ACT_FAILED, "failed to execute bpf obj action"} + {LIBPERF_ERR_BPF_ACT_FAILED, "failed to execute bpf obj action"}, + {LIBPERF_ERR_NULL_POINTER, "the input pointer cannot be null"} }; static std::unordered_map warnMsgs = { {LIBPERF_WARN_CTXID_LOST, "Some SPE context packets are not found in the traces."},