summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2014-10-04 20:25:02 -0700
committerJim Meyering <meyering@fb.com>2014-10-04 21:58:11 -0700
commitd43ec98e01b2135650bb677cab0c3dde53b0c399 (patch)
treebd23344d6b896bc3c2b07b18ff68a6044c6f39dd
parent4a9a21121c9156077a77a8587f8c43f8b940d259 (diff)
downloadgrep-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.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/grep.c b/src/grep.c
index 7475ea16..9dcf2982 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -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)