]> git.ipfire.org Git - thirdparty/coreutils.git/commit
od: fix some unlikely integer overflows
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 26 Jun 2025 06:22:37 +0000 (23:22 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Jun 2025 04:00:41 +0000 (21:00 -0700)
commit88f30ee0a5c355701914d4446dc7ec729a344fa2
treed8b8ac43f7462f0e9d47a9068236ca5814785155
parent35d9bf6915bff5d88dd2246ae5a157db838c64f1
od: fix some unlikely integer overflows

* src/od.c (print_n_spaces, pad_at, pad_at_overflow):
New static functions.
(struct tspec, PRINT_FIELDS, print_named_ascii, print_ascii)
(decode_one_format, write_block, main):
Use idx_t, not int, for counts that depend on the number
of bytes in an object.
(decode_one_format): Use print_n_spaces to output spaces.
(PRINT_FIELDS, print_named_ascii, print_ascii):
Use pad_at to avoid integer overflow.
(write_block): Do not use %*s to pad, as the total pad might
exceed INT_MAX.  Instead, pad by hand with putchar (' ').
(main): Use pad_at_overflow to report integer overflow due to
oversize -w.  Use better way to tell whether -w is used,
without needing IF_LINT.
* tests/od/big-w.sh: New test.
* tests/local.mk (all_tests): Add it.
NEWS
src/od.c
tests/local.mk
tests/od/big-w.sh [new file with mode: 0755]