diff options
author | Jim Meyering <meyering@redhat.com> | 2011-06-17 10:27:06 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-06-17 10:44:11 +0200 |
commit | 0b91d6928e9d098d3746ce9f4bb4160a2e685f5c (patch) | |
tree | af9847a7f810b291f37c5f14246203df45d2acff /tests/dfa-heap-overrun | |
parent | 9d60e79a26787b742a1f075ac96195b111f68af0 (diff) | |
download | grep-0b91d6928e9d098d3746ce9f4bb4160a2e685f5c.tar.gz |
dfa: don't overrun a malloc'd buffer for certain regexps
* src/dfa.c (dfaanalyze): Allocate space for twice as many
positions as there are leaves. Before this change, for some
regular expressions, DFA analysis would have inserted far more
"positions" than dfa->nleaves (up to double).
Reported by Raymond Russell in http://savannah.gnu.org/bugs/?33547
* tests/dfa-heap-overrun: Trigger the overrun.
* tests/Makefile.am (TESTS): Add it.
* NEWS (Bug fixes): Mention it.
Diffstat (limited to 'tests/dfa-heap-overrun')
-rwxr-xr-x | tests/dfa-heap-overrun | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/dfa-heap-overrun b/tests/dfa-heap-overrun new file mode 100755 index 00000000..dda1c12b --- /dev/null +++ b/tests/dfa-heap-overrun @@ -0,0 +1,26 @@ +#!/bin/sh +# Trigger a heap overrun in grep-2.6..grep-2.8. + +# Copyright (C) 2011 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +fail=0 + +grep -E '(^| )*(a|b)*(c|d)*( |$)' < /dev/null +test $? = 1 || fail=1 + +Exit $fail |