diff options
author | Jim Meyering <meyering@fb.com> | 2014-10-04 20:25:02 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2014-10-04 21:58:11 -0700 |
commit | d43ec98e01b2135650bb677cab0c3dde53b0c399 (patch) | |
tree | bd23344d6b896bc3c2b07b18ff68a6044c6f39dd | |
parent | 4a9a21121c9156077a77a8587f8c43f8b940d259 (diff) | |
download | grep-d43ec98e01b2135650bb677cab0c3dde53b0c399.tar.gz |
grep: avoid stack buffer read-underrun and overrun
Testing binaries built with -fsanitize=address caused aborts due
to stack underrun and overrun.
* src/grep.c (main): Allocate a larger buffer for eolbytes:
one byte before the beginning and one more after the end.
For details, see http://debbugs.gnu.org/18580#44.
-rw-r--r-- | src/grep.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -2513,9 +2513,10 @@ main (int argc, char **argv) compile (keys, keycc); free (keys); - char eolbytes[2] = { eolbyte }; + /* We need one byte prior and at least two after. */ + char eolbytes[4] = { 0, eolbyte, 0, 0 }; size_t match_size; - skip_empty_lines = ((execute (eolbytes, 1, &match_size, NULL) == 0) + skip_empty_lines = ((execute (eolbytes + 1, 1, &match_size, NULL) == 0) == out_invert); if ((argc - optind > 1 && !no_filenames) || with_filenames) |