Re: [PATCH v12 bpf-next 7/8] selftests/bpf: test kind encoding/decoding

[email protected]
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <c7c1696f1bf7ccc682cd27a6f1245555f21abeb79163865d82eec9438895e47f@mail.kernel.org>
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_kind.c b/tools/testing/selftests/bpf/prog_tests/btf_kind.c
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_kind.c

[ ... ]

> +static void write_raw_btf(const char *btf_path, void *raw_btf, size_t raw_size)
> +{
> +	int fd = open(btf_path, O_WRONLY | O_CREAT);
                                          ^^^^^^^^

Should this include a mode argument?  When O_CREAT is specified,
open() requires a third mode_t parameter.  Without it, the file
permissions are determined by whatever value happens to be on the
stack, since open() is variadic.

Something like this would avoid the undefined behavior:

    int fd = open(btf_path, O_WRONLY | O_CREAT | O_TRUNC, 0600);

> +
> +	write(fd, raw_btf, raw_size);
> +	close(fd);
> +}

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22637324186
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.