From: zhangmingyi <zhangmingyi5@xxxxxxxxxx> The sample_cb of the ring_buffer__new interface can transfer NULL. However, the system does not check whether sample_cb is NULL during ring_buffer__poll, null pointer is used. Signed-off-by: zhangmingyi <zhangmingyi5@xxxxxxxxxx> --- tools/lib/bpf/ringbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 02199364db13..3661338a1d2e 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -248,7 +248,7 @@ static int64_t ringbuf_process_ring(struct ring *r) got_new_data = true; cons_pos += roundup_len(len); - if ((len & BPF_RINGBUF_DISCARD_BIT) == 0) { + if (r->sample_cb && ((len & BPF_RINGBUF_DISCARD_BIT) == 0)) { sample = (void *)len_ptr + BPF_RINGBUF_HDR_SZ; err = r->sample_cb(r->ctx, sample, len); if (err < 0) { -- 2.33.0