NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/60860: nbperf: if -o and-m share the same name, the key file is truncated before it is read
>Number: 60860
>Category: bin
>Synopsis: nbperf: if -o and-m share the same name, the key file is truncated before it is read
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 07 14:50:00 +0000 2026
>Originator: João Matos
>Release: NetBSD-current (src trunk, git mirror commit 5601fdcca316, 2026-10-07)
>Organization:
Instituto Superior Técnico / Carnegie Mellon University
>Environment:
Linux thinkpad 6.12.111+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.111-1 (2026-09-28) x86_64 GNU/Linux
>Description:
nbperf opens the -o output (and the -m map file) with fopen(optarg, "w")
while it parses the options (usr.bin/nbperf/nbperf.c lines 185 and 175),
before it opens the key list (line 207). When the output shares the same name as the key list, the "w" open truncates it before a single key is
read. nbperf then reads zero keys, writes a hash for the empty set over
the file, and exits 0. The keys are lost and nothing reports an error.
A command such as "nbperf -o keys keys" (or "nbperf -m keys -o h.c
keys") is enough; there is no warning that the output and the input
are the same file.
Not run on NetBSD itself: the NetBSD trunk sources of usr.bin/nbperf
and common/lib/libc/stdlib/mi_vector_hash.c were built and run on
Debian GNU/Linux 13 (glibc 2.41, x86_64, gcc), with a small
compatibility header (sys/endian.h, le32dec, getprogname) that does not
touch the code involved. First found in the copy of nbperf carried by
https://github.com/ibara/mg.
>How-To-Repeat:
$ printf 'alpha\nbravo\ncharlie\n' > f
$ nbperf -o f f; echo $?
0
$ cat f # generated code for zero keys; the three keys are gone
With a different output (e.g. nbperf -o out.c f) the same keys produce a
normal hash.
>Fix:
Open the outputs only after the key list has been read and closed. With
this change "nbperf -o f f" writes the hash of the keys to f, which is
what a user would expect (as with sort -o f f).
Home |
Main Index |
Thread Index |
Old Index