> To be precise, > any use of --include or --exclude-from would also cause a segfault.
Here's the probably-final patch: >From c750d456c19d2523b6c6213e97df1ae434dd9da8 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Fri, 26 Mar 2010 11:34:27 +0100 Subject: [PATCH] grep: don't segfault upon use of --include or --exclude* options * lib/savedir.c (isdir1): Fix fatal typo: deref "dir" argument, not the global (initially-NULL) "path". Reported by Standish Parsley. * tests/include-exclude: New file. * tests/Makefile.am (TESTS): Add it. * NEWS (Bug fixes): Mention it. --- NEWS | 5 +++++ THANKS | 1 + lib/savedir.c | 2 +- tests/Makefile.am | 1 + tests/include-exclude | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletions(-) create mode 100644 tests/include-exclude diff --git a/NEWS b/NEWS index 115fe76..6d87655 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,11 @@ GNU grep NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + Using any of the --include or --exclude* options would cause a NULL + dereference. [bug introduced in 2.6] + ** Build-related configure no longer relies on pkg-config to detect PCRE support. diff --git a/THANKS b/THANKS index f7d8970..e1273de 100644 --- a/THANKS +++ b/THANKS @@ -73,6 +73,7 @@ Ruslan Ermilov <[email protected]> Santiago Vila <[email protected]> Shannon Hill <[email protected]> Sotiris Vassilopoulos <[email protected]> +Standish Parsley <[email protected]> Stewart Levin <[email protected]> Sven Joachim <[email protected]> Sydoruk Stepan <[email protected]> diff --git a/lib/savedir.c b/lib/savedir.c index 91fd77b..94e5f12 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -48,7 +48,7 @@ isdir1 (const char *dir, const char *file) size_t dirlen = strlen (dir); size_t filelen = strlen (file); - while (dirlen && path[dirlen - 1] == '/') + while (dirlen && dir[dirlen - 1] == '/') dirlen--; if ((dirlen + filelen + 2) > pathlen) diff --git a/tests/Makefile.am b/tests/Makefile.am index 8884daf..efbbcc0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,6 +33,7 @@ TESTS = \ fmbtest.sh \ foad1 \ help-version \ + include-exclude \ khadafy.sh \ max-count-vs-context \ options.sh \ diff --git a/tests/include-exclude b/tests/include-exclude new file mode 100644 index 0000000..e77c126 --- /dev/null +++ b/tests/include-exclude @@ -0,0 +1,32 @@ +#!/bin/sh +# Use of any --include or --exclude* option would segfault in 2.6 and 2.6.1 +: ${srcdir=.} +. "$srcdir/init.sh"; path_prepend_ ../src + +mkdir -p x/dir || framework_failure_ +echo a > x/a || framework_failure_ +echo b > x/b || framework_failure_ +echo d > x/dir/d || framework_failure_ + +printf '%s\n' x/b:b x/dir/d:d > exp-not-a || framework_failure_ +printf '%s\n' x/dir/d:d > exp-not-ab || framework_failure_ +printf '%s\n' x/a:a x/b:b > exp-not-d || framework_failure_ +printf '%s\n' x/a:a x/b:b > exp-not-dir || framework_failure_ + +grep -r --exclude='a*' . x > out || fail=1 +sort out > k && mv k out +compare out exp-not-a || fail=1 + +grep -r --exclude='[ab]' . x > out || fail=1 +sort out > k && mv k out +compare out exp-not-ab || fail=1 + +grep -r --exclude='*d' . x > out || fail=1 +sort out > k && mv k out +compare out exp-not-d || fail=1 + +grep -r --exclude-dir=dir . x > out || fail=1 +sort out > k && mv k out +compare out exp-not-dir || fail=1 + +Exit $fail -- 1.7.0.3.448.g82eeb
