Skip to contentSkip to conversation

libbpf: Fix null pointer when using old pref_buffer__new()

PATCH In review Yucong Sun 2 participants 2 messages Dec 2, 2021 – Dec 3, 2021

Subsystems (2)
lore
Share & tools
lore

Yucong Sun

author
#0 lore raw

PATCH 1/1 libbpf: Fix null pointer when using old pref_buffer__new()

Passing opts point to new function so program using old interface won't segfault.

Fixes 417889346577 ("libbpf: Make perf_buffer__new() use OPTS-based interface")
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 1341ce539662..dac4929e5810 100644
@@ -10812,7 +10812,7 @@ struct perf_buffer *perf_buffer__new_deprecated(int map_fd, size_t page_cnt,
 				       opts ? opts->sample_cb : NULL,
 				       opts ? opts->lost_cb : NULL,
 				       opts ? opts->ctx : NULL,
-				       NULL);
+				       opts);
 }
 
 DEFAULT_VERSION(perf_buffer__new_raw_v0_6_0, perf_buffer__new_raw, LIBBPF_0.6.0)
Signature · 1 line
2.30.2
#1 lore raw
Quoted 16 lines · Yucong Sun

Passing opts point to new function so program using old interface won't segfault.

Fixes 417889346577 ("libbpf: Make perf_buffer__new() use OPTS-based interface")
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index 1341ce539662..dac4929e5810 100644

tools/lib/bpf/libbpf.c struct perf_buffer *perf_buffer__new_deprecated(int map_fd, size_t page_cnt, · line 10815

Quoted 5 lines
tools/lib/bpf/libbpf.c +1 -1
@@ -10812,7 +10812,7 @@ struct perf_buffer *perf_buffer__new_deprecated(int map_fd, size_t page_cnt,
                                       opts ? opts->sample_cb : NULL,
                                       opts ? opts->lost_cb : NULL,
                                       opts ? opts->ctx : NULL,
-                                      NULL);
+                                      opts);

perf_buffer__new_v0_6_0() doesn't need non-null opts, OPTS_VALID(opts, perf_buffer_opts) handles NULL perfectly fine. After that we never dereference opts. That NULL there is intentional.

Quoted 6 lines
tools/lib/bpf/libbpf.c +0 -1
 }
 
 DEFAULT_VERSION(perf_buffer__new_raw_v0_6_0, perf_buffer__new_raw, LIBBPF_0.6.0)
--

2.30.2