zfs/cmd/zdb
Richard Yao f954ea26a6 zdb: Handle theoretical buffer overflow when printing float
CodeQL pointed out that for extreme floating point values, `sprintf()`
will overwrite a 32 character buffer. It cited 1e304 as an example,
which causes `sprintf()` to print 308 characters.

In practice, the numbers should never exceed 100, so this should not
happen. To silence the warning and also handle unexpected situations, we
change the code to use `snprintf()`.

This was missed during my audit of our use of `sprintf()`, since I did
not think to consider extreme floating point representations. It also
really should not happen, so this change is purely defensive
programming.

This was found by CodeQL's cpp/overrunning-write-with-float check.

Reviewed-by: Damian Szuberski <szuberskidamian@gmail.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14264
2022-12-08 14:15:15 -08:00
..
Makefile.am autoconf: use include directives instead of recursing down cmd 2022-05-10 10:18:38 -07:00
zdb.c zdb: Handle theoretical buffer overflow when printing float 2022-12-08 14:15:15 -08:00
zdb.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
zdb_il.c zfs_rename: support RENAME_* flags 2022-10-28 09:49:20 -07:00