> diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_map_dump.c
> b/tools/testing/selftests/bpf/prog_tests/bpftool_map_dump.c
> new file mode 100644
> index 000000000000..9c88743a8f84
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/bpftool_map_dump.c
> @@ -0,0 +1,465 @@
[ ... ]
> +static bool dump_map(__u32 id, const char *options, char *output)
> +{
> + char command[MAX_BPFTOOL_CMD_LEN];
> +
> + snprintf(command, sizeof(command), "%s map dump id %u", options, id);
> + memset(output, 0, OUTPUT_SIZE);
> + if (!ASSERT_OK(get_bpftool_command_output(command, output, OUTPUT_SIZE
> - 1),
> + "dump_map"))
> + return false;
> + /* The helper doesn't terminate or strip the output. */
> + output[strcspn(output, "\n")] = '\0';
> + return true;
> +}
Is the comment accurate? Looking at the helper's implementation in
tools/testing/selftests/bpf/bpftool_helpers.c, get_bpftool_command_output()
forwards to run_command(), which on the capture path does:
if (!suppress_output) {
n = fread(output_buf, 1, output_max_len - 1, f);
output_buf[n] = '\0';
}
Since dump_map() always passes a non-NULL buffer with a non-zero size,
suppress_output is false, so the helper does NUL-terminate the buffer.
The strcspn() line is only stripping the trailing newline, not adding
termination. Would "The helper leaves the trailing newline in place"
be more accurate?
---
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/34073252721