From owner-svn-src-all@freebsd.org Tue Aug 9 18:49:21 2016 Return-Path: Delivered-To: svn-src-all@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 15623BB4B06; Tue, 9 Aug 2016 18:49:21 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D616E1F6A; Tue, 9 Aug 2016 18:49:20 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u79InKYI050714; Tue, 9 Aug 2016 18:49:20 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u79InJqP050711; Tue, 9 Aug 2016 18:49:19 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201608091849.u79InJqP050711@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Tue, 9 Aug 2016 18:49:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r303882 - in stable/10/usr.bin/grep: . regex X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Aug 2016 18:49:21 -0000 Author: dim Date: Tue Aug 9 18:49:19 2016 New Revision: 303882 URL: https://svnweb.freebsd.org/changeset/base/303882 Log: MFC r270132 (by gabor): - Do not look for more matching lines if -L is specified Submitted by: eadler (based on) MFC r296799 (by ian): Fix a bug in bsdgrep that caused the program to hang in a tight loop for some combinations of command line options and search patterns. The code was examining regexec flags looking for a regcomp flag value. The fix is to look in the struct field where the decoded regcomp flag was stored when the regex was compiled. With this fix, it's possible to build WITHOUT_GNU_GREP_COMPAT and WITH_BSDGREP and have a usable GPL-free grep (which of course lacks gnugrep extensions). It now passes the kyua tests except for one test that requires the -z/--null-data gnu extension, and one test involving outputting context lines across multiple files which appears to sometimes output an extra delimiter line ("--") between matches (a rather obscure failure of a rather obscure feature, so bsdgrep should be generally usable now). MFC r303676: Fix a segfault in bsdgrep when parsing the invalid extended regexps "?" or "+" (these are invalid, because there is no preceding operand). When bsdgrep attempts to emulate GNU grep in discarding and ignoring the invalid ? or + operators, some later logic in tre_compile_fast() goes beyond the end of the buffer, leading to a crash. Fix this by bailing out, and reporting a bad pattern instead. Reported by: Steve Kargl Modified: stable/10/usr.bin/grep/regex/glue.h stable/10/usr.bin/grep/regex/tre-fastmatch.c stable/10/usr.bin/grep/util.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/grep/regex/glue.h ============================================================================== --- stable/10/usr.bin/grep/regex/glue.h Tue Aug 9 17:57:11 2016 (r303881) +++ stable/10/usr.bin/grep/regex/glue.h Tue Aug 9 18:49:19 2016 (r303882) @@ -50,7 +50,7 @@ typedef enum { STR_WIDE, STR_BYTE, STR_M if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0) \ return REG_NOMATCH; \ ret = fn; \ - for (unsigned i = 0; (!(eflags & REG_NOSUB) && (i < nmatch)); i++)\ + for (unsigned i = 0; (!preg->nosub && (i < nmatch)); i++) \ { \ pmatch[i].rm_so += offset; \ pmatch[i].rm_eo += offset; \ Modified: stable/10/usr.bin/grep/regex/tre-fastmatch.c ============================================================================== --- stable/10/usr.bin/grep/regex/tre-fastmatch.c Tue Aug 9 17:57:11 2016 (r303881) +++ stable/10/usr.bin/grep/regex/tre-fastmatch.c Tue Aug 9 18:49:19 2016 (r303882) @@ -621,7 +621,7 @@ tre_compile_fast(fastmatch_t *fg, const case TRE_CHAR('+'): case TRE_CHAR('?'): if ((cflags & REG_EXTENDED) && (i == 0)) - continue; + goto badpat; else if ((cflags & REG_EXTENDED) ^ !escaped) STORE_CHAR; else Modified: stable/10/usr.bin/grep/util.c ============================================================================== --- stable/10/usr.bin/grep/util.c Tue Aug 9 17:57:11 2016 (r303881) +++ stable/10/usr.bin/grep/util.c Tue Aug 9 18:49:19 2016 (r303882) @@ -336,7 +336,7 @@ procline(struct str *l, int nottext) } /* One pass if we are not recording matches */ - if (!wflag && ((color == NULL && !oflag) || qflag || lflag)) + if (!wflag && ((color == NULL && !oflag) || qflag || lflag || Lflag)) break; if (st == (size_t)pmatch.rm_so)