HomeFreeBSD

Cleanup dump_bookmarks()

Description

Cleanup dump_bookmarks()

Assertions are meant to check assumptions, but the way that this
assertion is written does not check an assumption, since it is provably
always true. Removing the assertion will cause a compiler warning (made
into an error by -Werror) about printing up to 512 bytes to a 256-byte
buffer, so instead, we change the assertion to verify the assumption
that we never do a snprintf() that is truncated to avoid overrunning the
256-byte buffer.

This was caught by an audit of the codebase to look for misuse of
snprintf() after CodeQL reported that we had misused snprintf(). An
explanation of how snprintf() can be misused is here:

https://www.redhat.com/en/blog/trouble-snprintf

This particular instance did not misuse snprintf(), but it was caught
by the audit anyway.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14098

Details

Provenance
Richard Yao <richard.yao@alumni.stonybrook.edu>Authored on Oct 27 2022, 7:41 PM
Brian Behlendorf <behlendorf1@llnl.gov>Committed on Oct 29 2022, 8:05 PM
Parents
rGd71d69326116: Fix too few arguments to formatting function
Branches
Unknown
Tags
Unknown

Event Timeline

Brian Behlendorf <behlendorf1@llnl.gov> committed rG2e08df84d864: Cleanup dump_bookmarks() (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Oct 29 2022, 8:05 PM