From: Yuan Chen <[email protected]>
bpftool's map dump closes the map fd twice: map_dump() closes it on both
its success and error paths, and do_dump() closes the same fd again.
This leaves errno set to EBADF after a dump.
The batch subcommand then misinterprets that stale errno: do_batch()
checks errno after reading the batch file to detect I/O failures, but
fgets() does not clear errno on success, so a leftover EBADF makes
bpftool report a spurious "reading batch file failed" error and exit
non-zero even though every command succeeded.
Patch 1 makes do_dump() the sole owner of the map fd by removing the
close from map_dump(), eliminating the double close and the EBADF source.
Patch 2 makes do_batch() use ferror() to detect genuine read failures
and tracks the too-long-line case explicitly, so stale errno can no
longer trigger a spurious error from any other source either.
Yuan Chen (2):
bpftool: fix double close in map dump
bpftool: fix spurious batch file read error
tools/bpf/bpftool/main.c | 8 ++++++--
tools/bpf/bpftool/map.c | 1 -
2 files changed, 6 insertions(+), 3 deletions(-)
--
2.54.0
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.