mirror of
https://https.git.savannah.gnu.org/git/grep.git
synced 2026-01-26 15:39:06 +00:00
grep: very long lines no longer evoke unwarranted "memory exhausted"
When calling xpalloc (NULL, &n, incr_min, alloc_max, 1) with nontrivial ALLOC_MAX, this must hold: N + INCR_MIN <= ALLOC_MAX. With a very long line, it did not, and grep would mistakenly fail with a report of "memory exhausted". * src/grep.c (fillbuf): When using nontrivial ALLOC_MAX, ensure it is at least N+INCR_MIN. * tests/fillbuf-long-line: New file, to test for this. * tests/Makefile.am (TESTS): Add its name.
This commit is contained in:
parent
efe1e1543c
commit
6e95551ad6
@ -984,7 +984,7 @@ fillbuf (idx_t save, struct stat const *st)
|
||||
ptrdiff_t a;
|
||||
if (0 <= to_be_read
|
||||
&& INT_ADD_OK (to_be_read, save + min_after_buflim, &a))
|
||||
alloc_max = a;
|
||||
alloc_max = MAX (a, bufalloc + incr_min);
|
||||
}
|
||||
|
||||
newbuf = xpalloc (NULL, &bufalloc, incr_min, alloc_max, 1);
|
||||
|
||||
@ -104,6 +104,7 @@ TESTS = \
|
||||
fgrep-longest \
|
||||
file \
|
||||
filename-lineno.pl \
|
||||
fillbuf-long-line \
|
||||
fmbtest \
|
||||
foad1 \
|
||||
grep-dev-null \
|
||||
|
||||
11
tests/fillbuf-long-line
Executable file
11
tests/fillbuf-long-line
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
# This would fail for v3.7-15-ge3694e9 .. grep-v3.7-48-g5c3c427
|
||||
. "${srcdir=.}/init.sh"; path_prepend_ ../src
|
||||
|
||||
printf %0104681d 0 > in || framework_failure_
|
||||
|
||||
fail=0
|
||||
|
||||
returns_ 1 grep xx in || fail=1
|
||||
|
||||
Exit $fail
|
||||
Loading…
x
Reference in New Issue
Block a user