linux/tools/testing/selftests/bpf/progs/snprintf_btf_void.c
Jiayuan Chen 1ae6aa6195 selftests/bpf: Add test for showing a void BTF type
Extend the snprintf_btf test with type_ids from the vmlinux BTF that
used to NULL-deref in the BTF show path: a "const void", checked to
render the "<unsupported kind:0>" placeholder, and a BTF_KIND_VAR,
checked to resolve and render without error.

The program renders from its own buffer and the test picks a VAR whose
resolved type fits it, so the render stays in bounds.

Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Link: https://lore.kernel.org/r/20260901104924.346187-6-jiayuan.chen@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2026-09-03 09:31:52 -07:00

25 lines
463 B
C

// SPDX-License-Identifier: GPL-2.0
#include "btf_ptr.h"
#include <bpf/bpf_helpers.h>
__u32 type_id;
/* A buffer we own to render the selected type from, kept in bounds. */
char obj[256];
char out[64];
long ret;
SEC("raw_tp/sys_enter")
int dump_type(void *ctx)
{
struct btf_ptr ptr = {
.ptr = obj,
.type_id = type_id,
.flags = 0,
};
ret = bpf_snprintf_btf(out, sizeof(out), &ptr, sizeof(ptr), 0);
return 0;
}
char _license[] SEC("license") = "GPL";