lkml.org 
[lkml]   [2023]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] libbpf:fix use empty function pointers in ringbuf_poll
Date
From: zhangmingyi <zhangmingyi5@huawei.com>

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@huawei.com>
---
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
\
 
 \ /
  Last update: 2023-06-05 05:36    [W:0.091 / U:1.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site