Bug 193835 - bug in GNU grep with -m and -A
Summary: bug in GNU grep with -m and -A
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: gnu (show other bugs)
Version: 10.0-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-22 13:44 UTC by aborche
Modified: 2017-11-22 03:21 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aborche 2014-09-22 13:44:52 UTC
grep segfault

create a file test.txt
-------------
text
text
<blank line>
text
text
-------------

run command: grep -m 1 -A 2 -e '^$' test.txt
> Segmentation Fault (core dumped)

in file test.txt add to end blank line

run grep again.
Result: none

Change -m1 to -m2
Result: all is ok
Comment 1 aborche 2014-09-22 13:54:36 UTC
http://dpaste.com/3VPJ869
Comment 2 Veniamin Gvozdikov freebsd_committer 2014-09-22 14:35:47 UTC
Copied gdb output from link, because it will expired through 1 day.

main:[~] %> gdb grep
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
(gdb) r -m 1 -A 2 -e '^$' text.test
Starting program: /usr/bin/grep -m 1 -A 2 -e '^$' text.test
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...

Program received signal SIGSEGV, Segmentation fault.
0x0000000800fb1a60 in memchr () from /lib/libc.so.7
(gdb) thread apply all bt
(gdb) bt
#0  0x0000000800fb1a60 in memchr () from /lib/libc.so.7
#1  0x000000000040ff92 in ?? ()
#2  0x000000000040d090 in ?? ()
#3  0x000000000040c5c9 in ?? ()
#4  0x000000000040bd52 in ?? ()
#5  0x000000000040260f in ?? ()
#6  0x0000000800633000 in ?? ()
#7  0x0000000000000000 in ?? ()
(gdb) f 0
#0  0x0000000800fb1a60 in memchr () from /lib/libc.so.7
(gdb)
Comment 3 Kyle Evans freebsd_committer 2017-04-20 17:19:19 UTC
This is indeed an issue with gnugrep, and not with libgnuregex. This one goes away when bsdgrep is installed as /usr/bin/grep, and can safely go away at that time.