From owner-freebsd-hackers@freebsd.org Mon Aug 1 16:21:59 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 70868BAA326; Mon, 1 Aug 2016 16:21:59 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:7b8:3a7:1:2d0:b7ff:fea0:8c26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 38DF2192B; Mon, 1 Aug 2016 16:21:59 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:7b8:3a7::d857:c5e3:f7:85c] (unknown [IPv6:2001:7b8:3a7:0:d857:c5e3:f7:85c]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 431B514D3D; Mon, 1 Aug 2016 18:21:56 +0200 (CEST) Subject: Re: BSD grep dumps core Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: multipart/signed; boundary="Apple-Mail=_56E280E6-6C8C-4D30-B32E-3A3B0932FE1F"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Pgp-Agent: GPGMail 2.6.1 From: Dimitry Andric In-Reply-To: <20160731153738.GA33643@troutmask.apl.washington.edu> Date: Mon, 1 Aug 2016 18:22:16 +0200 Cc: FreeBSD Current , FreeBSD Hackers Message-Id: <54B0B5B7-25CF-4B7D-9874-73D33481CC1C@FreeBSD.org> References: <20160731153738.GA33643@troutmask.apl.washington.edu> To: Steve Kargl X-Mailer: Apple Mail (2.3124) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2016 16:21:59 -0000 --Apple-Mail=_56E280E6-6C8C-4D30-B32E-3A3B0932FE1F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 31 Jul 2016, at 17:37, Steve Kargl = wrote: >=20 > Script started on Sun Jul 31 08:30:56 2016 > troutmask:sgk[200] cd gcc/gcc7 > troutmask:sgk[201] svn status > ? 7.diff > ? decl.c.diff > ? gcc/fortran/old > ? gcc/fortran/pr38351.diff > ? gcc/fortran/pr41922.diff > ? gcc/fortran/pr69860.diff > ? trans-decl.c.diff > ? typescript > ? z1.diff > troutmask:sgk[202] svn status | grep -v -E ^\? > Segmentation fault (core dumped) > troutmask:sgk[203] svn status | grep -v -E ^"\?" > troutmask:sgk[204] exit > exit >=20 > Script done on Sun Jul 31 08:31:54 2016 >=20 > The core dump happens with both tcsh and sh. >=20 > The following works as expected >=20 > troutmask:sgk[202] svn status | gnugrep -v -E ^\? Yes, '^?' is an invalid extended regular expression, but GNU grep does not complain about it, and simply discards the '?' character. Our BSD grep dies because it also attempts to discard, but then some later logic goes beyond the end of the buffer. Please try this fix: Index: usr.bin/grep/regex/tre-fastmatch.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- usr.bin/grep/regex/tre-fastmatch.c (revision 303551) +++ usr.bin/grep/regex/tre-fastmatch.c (working copy) @@ -621,7 +621,7 @@ tre_compile_fast(fastmatch_t *fg, const tre_char_t case TRE_CHAR('+'): case TRE_CHAR('?'): if ((cflags & REG_EXTENDED) && (i =3D=3D 0)) - continue; + goto badpat; else if ((cflags & REG_EXTENDED) ^ !escaped) STORE_CHAR; else After this, bsdgrep errors out with: % bsdgrep -E '^?' bsdgrep: Invalid preceding regular expression which is much saner IMHO. -Dimitry --Apple-Mail=_56E280E6-6C8C-4D30-B32E-3A3B0932FE1F Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.30 iEYEARECAAYFAlefdzwACgkQsF6jCi4glqN/fACguF9Gh9i4kCUA936CLMlMHnCZ +4oAn1iuihtI/htbER4YTHFqym/hQbJ3 =zfdm -----END PGP SIGNATURE----- --Apple-Mail=_56E280E6-6C8C-4D30-B32E-3A3B0932FE1F--