Red Hat Bugzilla – Bug 452127
grep segfaults when using -m and -A
Last modified: 2013-04-12 15:46:27 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:126.96.36.199) Gecko/20080404 Iceweasel/188.8.131.52 (Debian-184.108.40.206-2)
Description of problem:
I can get grep to crash (segfault) when using a certain combination of
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. echo -en "X\nX" | /bin/grep -m 1 -A 1 '.*X'
It should not segfault.
When running with grep-debuginfo-2.5.1-54.2.el5 installed and using grep:
$ echo -en "X\nX" > /tmp/testinput.txt
$ gdb /bin/grep
GNU gdb Red Hat Linux (6.5-37.el5rh)
Copyright (C) 2006 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 "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run -m 1 -A 1 '.*X' /tmp/testinput.txt
Starting program: /bin/grep -m 1 -A 1 '.*X' /tmp/testinput.txt
Program received signal SIGSEGV, Segmentation fault.
0x001e4d89 in memchr () from /lib/libc.so.6
#0 0x001e4d89 in memchr () from /lib/libc.so.6
#1 0x08052e15 in kwsexec (kws=0x98d8ff8,
text=0x1 <Address 0x1 out of bounds>, size=160280578, kwsmatch=0xbf9fbadc)
#2 0x08055112 in EGexecute (buf=0x98db002 "X\n", size=1,
match_size=0xbf9fbb38, exact=0) at search.c:386
#3 0x0804a68c in prpending (lim=0x98db004 "") at grep.c:598
#4 0x0804b45d in grepfile (file=0xbf9fcc4b "/tmp/testinput.txt",
stats=0x805b2e0) at grep.c:846
#5 0x0804c2cd in main (argc=7, argv=0xbf9fbd14) at grep.c:1745
#6 0x0018adec in __libc_start_main () from /lib/libc.so.6
#7 0x080497f1 in _start ()
The issue is fixed upstream by the following patch
This request was evaluated by Red Hat Product Management for
inclusion, but this component is not scheduled to be updated in
the current Red Hat Enterprise Linux release. If you would like
this request to be reviewed for the next minor release, ask your
support representative to set the next rhel-x.y flag to "?".
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.