On Sun, 05 Oct 2014 12:33:45 +0900 Norihiro Tanaka <nori...@kcn.ne.jp> wrote:
> find_pred function is return an address to NULL pointer, but I think we > don't hope it. So fix it. > > BTW, it could never happen, as the syntax is checked in regex prior to it. I wrote and added a test driver for this bug which uses a program `dfa-match-aux' added for tests recently. The program will generate a core dump before the change.
From 4a28f583f45b69b2ef0ce3cd7375cc8b42262600 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka <nori...@kcn.ne.jp> Date: Sun, 5 Oct 2014 12:09:24 +0900 Subject: [PATCH] dfa: return NULL as can't find any predicates. * src/dfa.c (find_pred): Return NULL as can't find any predicates. * tests/invalid-char-class: Add a new test. * tests/Makefile.am: Add a rule to build new test. (TESTS): Add invalid-char-class. --- src/dfa.c | 5 ++--- tests/Makefile.am | 1 + tests/invalid-char-class | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 tests/invalid-char-class diff --git a/src/dfa.c b/src/dfa.c index 806cb04..133b43d 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -971,9 +971,8 @@ find_pred (const char *str) unsigned int i; for (i = 0; prednames[i].name; ++i) if (STREQ (str, prednames[i].name)) - break; - - return &prednames[i]; + return &prednames[i]; + return NULL; } /* Multibyte character handling sub-routine for lex. diff --git a/tests/Makefile.am b/tests/Makefile.am index 67c165d..ce0114f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -74,6 +74,7 @@ TESTS = \ include-exclude \ inconsistent-range \ invalid-multibyte-infloop \ + invalid-char-class \ khadafy \ long-line-vs-2GiB-read \ match-lines \ diff --git a/tests/invalid-char-class b/tests/invalid-char-class new file mode 100755 index 0000000..0cb087f --- /dev/null +++ b/tests/invalid-char-class @@ -0,0 +1,30 @@ +#!/bin/sh +# This would fail for grep-2.21. + +# Copyright 2014 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 + +# Add "." to PATH for the use of dfa-match-aux. +path_prepend_ . + +fail=0 + +echo 'dfaerror: invalid character class' > exp +LC_ALL=C dfa-match-aux '[[:foo:]]' a > out 2>&1 +compare exp out || fail=1 + +Exit $fail -- 2.2.0