mirror of
https://github.com/coreutils/coreutils.git
synced 2026-10-28 09:44:34 +08:00
pr: guard input position update against overflow
* src/pr.c (char_to_clump): Use ckd_add() and report integer overflow. * tests/pr/options.sh: Add a test case. * NEWS: Mention the bug fix. Fixes https://bugs.gnu.org/81393
This commit is contained in:
1 parent
36d1a194a9
commit
9342ddbd71
3 files changed
+19
-1
No files matched your search
@@ -26,6 +26,10 @@ GNU coreutils NEWS -*- outline -*-
|
||||
standard output is fully buffered, e.g., when redirected to a file.
|
||||
[bug introduced in coreutils-9.10]
|
||||
|
||||
'pr' now exits gracefully upon exceeding internal accounting limits,
|
||||
like when processing large tab stops.
|
||||
[This bug was present in "the beginning".]
|
||||
|
||||
'shred' no longer blocks when opening a FIFO that has no readers.
|
||||
[This bug was present in "the beginning".]
|
||||
|
||||
|
||||
@@ -2732,7 +2732,10 @@ char_to_clump (char c)
|
||||
else if (width < 0 && input_position <= -width)
|
||||
input_position = 0;
|
||||
else
|
||||
input_position += width;
|
||||
{
|
||||
if (ckd_add (&input_position, input_position, width))
|
||||
integer_overflow ();
|
||||
}
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
@@ -57,4 +57,15 @@ printf '%s\n' "pr: '-e' extra characters or $INV in the argument: '-1'" \
|
||||
>exp || framework_failure_
|
||||
compare exp err || fail=1
|
||||
|
||||
# Ensure we exit gracefully upon internal overflow limits
|
||||
# Tag as expensive as it uses little mem, but about 10s on a 2020 class machine.
|
||||
if { test "$RUN_VERY_EXPENSIVE_TESTS" = yes ||
|
||||
test "$RUN_EXPENSIVE_TESTS" = yes; } &&
|
||||
test "$INT_MAX" = 2147483647; then # restrict to usual 32 bit limits
|
||||
head -c1M /dev/zero | tr '\0' '\t' |
|
||||
returns_ 1 pr -t -e$(($INT_MAX/(1024*1024) + 1)) 2>err >/dev/null || fail=1
|
||||
printf '%s\n' "pr: integer overflow" > exp || framework_failure_
|
||||
compare exp err || fail=1
|
||||
fi
|
||||
|
||||
Exit $fail
|
||||
Reference in new issue
Block a user