buggrep - Bugs: bug #29358, segmentation fault in isdir1 with...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #29358: segmentation fault in isdir1 with grep-2.6.1

Submitted by:  -Deleted Account- <bjg>
Submitted on:  Sat 27 Mar 2010 11:39:02 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Closed

(Jump to the original submission Jump to the original submission)

Sun 28 Mar 2010 06:22:42 PM UTC, comment #6:

I forgot, this one to main.c, manpage reads:

--include=GLOB
Search only files whose base name matches GLOB (using wildcard
matching as described under --exclude).

Which currently doesn't happens unless EXCLUDE_WILDCARDS is also on add_exclude() options:

--- grep-2.6.1/src/main.c.orig
+++ grep-2.6.1/src/main.c
@@ -2066,7 +2066,7 @@
case INCLUDE_OPTION:
if (!included_patterns)
included_patterns = new_exclude ();
- add_exclude (included_patterns, optarg, EXCLUDE_INCLUDE);
+ add_exclude (included_patterns, optarg, EXCLUDE_INCLUDE | EXCLUDE_WILDCARDS);
break;

case GROUP_SEPARATOR_OPTION:

Javier Villavicencio <the_paya>
Sun 28 Mar 2010 06:11:17 PM UTC, comment #5:

Try this little patch to exclude.c:

--- grep-2.6.1/lib/exclude.c.orig
+++ grep-2.6.1/lib/exclude.c
@@ -342,7 +342,7 @@
{
char const *pattern = exclude[i].pattern;
int options = exclude[i].options;
- if (excluded != exclude_fnmatch (pattern, f, options))
+ if (exclude_fnmatch (pattern, f, options))
return !excluded;
}
return excluded;

If I got the logic right, then exclude_fnmatch() should return !excluded on string match, not depending on if EXCLUDE_INCLUDE was set.

Javier Villavicencio <the_paya>
Sun 28 Mar 2010 05:53:06 PM UTC, comment #4:

I can't figure out how to build from the git tree, so I applied your patch to the 2.6.1 tarball. With that patch, using the --include switch causes grep not to find anything anymore.

If the patch works fine when applying to the git tree, leave this closed; otherwise, please re-open. (Or would you prefer me to file a new bug report with a more pertinent title?)

(Also, how do you build grep from the git tree?)

Philipp Kohlbecher <xt28>
Sun 28 Mar 2010 03:42:20 PM UTC, comment #3:

Thanks for mentioning that. I've posted a patch to the bug-grep mailing list. I'm closing this, but you're welcome to re-open if somehow it's not fixed.

Jim Meyering <meyering>
Project Administrator
Sun 28 Mar 2010 02:00:17 PM UTC, comment #2:

Just noticed the fix in the git repo. While it makes a lot more sense than my hack below, that fix also leaves the --include switch non-functional.

Philipp Kohlbecher <xt28>
Sun 28 Mar 2010 10:34:37 AM UTC, comment #1:

This is a null pointer dereference in isdir1. The pointer in question is "path" which is used in isdir1 before being assigned.

Looking at lib/savedir.c, I can't figure out what this "path" variable is used for.

Simply setting
pathlen = dirlen + filelen + 2;
path = xrealloc (path, pathlen);
in isdir1 will fix the segfault.

With this fix in place, the --include switch doesn't work, though.

Philipp Kohlbecher <xt28>
Sat 27 Mar 2010 11:39:02 AM UTC, original submission:

On fencepost.gnu.org there is a segmentation fault showing up in grep-2.6.1 in recursive grep with --include with empty subdirectories. The complete build log for grep is at /gd/gnu/gnusys/logs/grep-2.6.1.log

Test case:

bjg@fencepost:~/ftp/foo$ mkdir emptydir
bjg@fencepost:~/ftp/foo$ mkdir emptydir/1
bjg@fencepost:~/ftp/foo$ mkdir emptydir/2
bjg@fencepost:~/ftp/foo$ grep -r --include='*.am' -i ICONV emptydir
Segmentation fault

bjg@fencepost:~/ftp/foo$ gdb grep
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(gdb) run -r --include='*.am' -i ICONV emptydir
Starting program: /srv/data/home/g/gnu/gnusys/live/bin/grep -r --include='*.am' -i ICONV emptydir

Program received signal SIGSEGV, Segmentation fault.
0x000000000040f180 in isdir1 (dir=0x7fff36bd26ca "emptydir", file=0x1e18afb "1") at savedir.c:51
51 savedir.c: No such file or directory.
in savedir.c
(gdb) bt
#0 0x000000000040f180 in isdir1 (dir=0x7fff36bd26ca "emptydir", file=0x1e18afb "1") at savedir.c:51
#1 0x000000000040f2f5 in savedir (dir=<value optimized out>, name_size=22, included_patterns=<value optimized out>,
excluded_patterns=0x0, excluded_directory_patterns=<value optimized out>) at savedir.c:112
#2 0x00000000004068e9 in grepdir (dir=0x7fff36bd26ca "emptydir", stats=0x6281e0) at main.c:1339
#3 0x0000000000405136 in grepfile (file=0x7fff36bd26ca "emptydir", stats=0x6281e0) at main.c:1083
#4 0x0000000000405adc in main (argc=6, argv=0x7fff36bd0888) at main.c:2193
(gdb)

bjg@fencepost:~/ftp/foo$ grep --version
GNU grep 2.6.1

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

-Deleted Account- <bjg>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by the_paya (Posted a comment)
  • -unavailable- added by meyering (Posted a comment)
  • -unavailable- added by xt28 (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 28 Mar 2010 03:42:20 PM UTCmeyeringOpen/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1