From ache@pobrecita.freebsd.ru  Sat Nov 17 03:08:56 2012
Return-Path: <ache@pobrecita.freebsd.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 39890831
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Nov 2012 03:08:56 +0000 (UTC)
	(envelope-from ache@pobrecita.freebsd.ru)
Received: from pobrecita.freebsd.ru (pobrecita.freebsd.ru [194.87.13.42])
	by mx1.freebsd.org (Postfix) with ESMTP id AD0208FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Nov 2012 03:08:55 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
	by pobrecita.freebsd.ru (8.14.5/8.14.5) with ESMTP id qAH35a6c041317
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Nov 2012 07:05:36 +0400 (MSK)
	(envelope-from ache@pobrecita.freebsd.ru)
Received: (from ache@localhost)
	by localhost (8.14.5/8.14.5/Submit) id qAH35ZVM041316;
	Sat, 17 Nov 2012 07:05:35 +0400 (MSK)
	(envelope-from ache)
Message-Id: <201211170305.qAH35ZVM041316@localhost>
Date: Sat, 17 Nov 2012 07:05:35 +0400 (MSK)
From: Andrey Chernov <ache@freebsd.org>
Reply-To: Andrey Chernov <ache@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: BSD fgrep -v is broken for multi-line pattern
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         173673
>Category:       bin
>Synopsis:       BSD fgrep cannot handle multiple patterns specified as one command-line argument
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gabor
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 17 03:10:00 UTC 2012
>Closed-Date:    
>Last-Modified:  Sat Jan 05 16:38:03 UTC 2013
>Originator:     Andrey Chernov
>Release:        FreeBSD 9.1-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD xxxxxxxxx.xxxxxxx.xx 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #5 r242933: Tue Nov 13 06:04:18 MSK 2012 ache@xxxxxxxxx.xxxxxxx.xx:/sys/i386/compile/POBRECITA i386

>Description:
	BSD fgrep -v do different things than gnu fgrep for multi-line
	pattern. Run following simple test. For BSD fgrep it prints
1
2
3
	and for gnu fgrep it correctly prints
3
>How-To-Repeat:
------------------------ cut here ----------------------
#!/bin/csh

(echo 1; echo 2; echo 3) | fgrep -v "1\
2"

(echo 1; echo 2; echo 3) | gnugrep -F -v "1\
2"
------------------------ cut here ----------------------
>Fix:

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->gabor 
Responsible-Changed-By: ache 
Responsible-Changed-When: Wed Nov 21 05:36:30 UTC 2012 
Responsible-Changed-Why:  
Assign to bsdgrep maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173673 

From: Andrey Chernov <ache@freebsd.org>
To: Andrey Chernov <ache@FreeBSD.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/173673: BSD fgrep -v is broken for multi-line pattern
Date: Mon, 31 Dec 2012 22:49:06 +0400

 Better test case including GNU grep from ports too (correct result) and
 always using absolute paths to avoid possible confusion. Also note that
 first line is /bin/csh not /bin/sh (newline escapes are different).
 
 #!/bin/csh
 
 (echo 1; echo 2; echo 3) | /usr/bin/fgrep -v "1\
 2"
 
 (echo 1; echo 2; echo 3) | /usr/local/bin/grep -F -v "1\
 2"
 
 (echo 1; echo 2; echo 3) | /usr/bin/gnugrep -F -v "1\
 2"
 
 Output:
 1
 2
 3
 3
 3
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/173673: commit references a PR
Date: Sat,  5 Jan 2013 14:52:44 +0000 (UTC)

 Author: gabor
 Date: Sat Jan  5 14:52:31 2013
 New Revision: 245057
 URL: http://svnweb.freebsd.org/changeset/base/245057
 
 Log:
   - Fix handling of the case when multiple patterns are specified in a single
     command line argument, separated by newlines
   
   PR:		bin/173673
   Submitted by:	ache
   MFC after:	1 week
 
 Modified:
   head/usr.bin/grep/grep.c
 
 Modified: head/usr.bin/grep/grep.c
 ==============================================================================
 --- head/usr.bin/grep/grep.c	Sat Jan  5 11:13:48 2013	(r245056)
 +++ head/usr.bin/grep/grep.c	Sat Jan  5 14:52:31 2013	(r245057)
 @@ -479,7 +479,13 @@ main(int argc, char *argv[])
  			grepbehave = GREP_EXTENDED;
  			break;
  		case 'e':
 -			add_pattern(optarg, strlen(optarg));
 +			{
 +				char *token;
 +				char *string = strdup(optarg);
 +
 +				while ((token = strsep(&string, "\n")) != NULL)
 +					add_pattern(token, strlen(token));
 +			}
  			needpattern = 0;
  			break;
  		case 'F':
 @@ -668,7 +674,11 @@ main(int argc, char *argv[])
  
  	/* Process patterns from command line */
  	if (aargc != 0 && needpattern) {
 -		add_pattern(*aargv, strlen(*aargv));
 +		char *token;
 +		char *string = strdup(*aargv);
 +
 +		while ((token = strsep(&string, "\n")) != NULL)
 +			add_pattern(token, strlen(token));
  		--aargc;
  		++aargv;
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: gabor 
State-Changed-When: Sat Jan 5 16:37:00 UTC 2013 
State-Changed-Why:  
Committed to HEAD, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173673 
>Unformatted:
