From owner-freebsd-bugs@FreeBSD.ORG Mon Sep 19 20:40:06 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4C101106564A for ; Mon, 19 Sep 2011 20:40:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 2935B8FC12 for ; Mon, 19 Sep 2011 20:40:06 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p8JKe6nb005306 for ; Mon, 19 Sep 2011 20:40:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p8JKe6lW005305; Mon, 19 Sep 2011 20:40:06 GMT (envelope-from gnats) Resent-Date: Mon, 19 Sep 2011 20:40:06 GMT Resent-Message-Id: <201109192040.p8JKe6lW005305@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Toby Peterson Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 091641065672 for ; Mon, 19 Sep 2011 20:37:07 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id D37998FC0A for ; Mon, 19 Sep 2011 20:37:06 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p8JKb6O5039510 for ; Mon, 19 Sep 2011 20:37:06 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p8JKb67B039509; Mon, 19 Sep 2011 20:37:06 GMT (envelope-from nobody) Message-Id: <201109192037.p8JKb67B039509@red.freebsd.org> Date: Mon, 19 Sep 2011 20:37:06 GMT From: Toby Peterson To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/160834: grep: fixes for POSIX conformance X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2011 20:40:06 -0000 >Number: 160834 >Category: bin >Synopsis: grep: fixes for POSIX conformance >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Sep 19 20:40:05 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Toby Peterson >Release: n/a >Organization: Apple Inc. >Environment: n/a >Description: Standard is at http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html Fairly straightforward changes, description as follows: fastgrep.c: Handle ^$ pattern correctly. Simple test is `echo | grep "^$"` - it should match the single line. grep.c: As described in the standard, "The pattern_list's value shall consist of one or more patterns separated by characters" util.c: For the purposes of the standard, inaccessible = nonexistent. Also don't match the empty end of the line. Simple test for that: `echo abc#def | grep "^[A-Za-z0-9]*$"` should not match anything. >How-To-Repeat: See description for test cases. >Fix: Patch attached. Patch attached with submission follows: Index: fastgrep.c =================================================================== --- fastgrep.c (revision 225675) +++ fastgrep.c (working copy) @@ -104,6 +104,10 @@ pat++; } + if (fg->len == 0) { + return (-1); + } + if (fg->len >= 14 && memcmp(pat, "[[:<:]]", 7) == 0 && memcmp(pat + fg->len - 7, "[[:>:]]", 7) == 0) { Index: grep.c =================================================================== --- grep.c (revision 225675) +++ grep.c (working copy) @@ -280,6 +280,21 @@ } /* + * Adds search patterns from arguments. + */ +static void +add_arg_patterns(const char *arg) +{ + char *argcopy, *pattern; + + argcopy = grep_strdup(arg); + while ((pattern = strsep(&argcopy, "\n")) != NULL) { + add_pattern(pattern, strlen(pattern)); + } + free(argcopy); +} + +/* * Reads searching patterns from a file and adds them with add_pattern(). */ static void @@ -461,7 +476,7 @@ grepbehave = GREP_EXTENDED; break; case 'e': - add_pattern(optarg, strlen(optarg)); + add_arg_patterns(optarg); needpattern = 0; break; case 'F': @@ -636,7 +651,7 @@ /* Process patterns from command line */ if (aargc != 0 && needpattern) { - add_pattern(*aargv, strlen(*aargv)); + add_arg_patterns(*aargv); --aargc; ++aargv; } Index: util.c =================================================================== --- util.c (revision 225675) +++ util.c (working copy) @@ -194,7 +194,7 @@ if (f == NULL) { if (!sflag) warn("%s", fn); - if (errno == ENOENT) + if (errno == ENOENT || errno == EACCES) notfound = true; return (0); } @@ -282,7 +282,7 @@ if (!matchall) { /* Loop to process the whole line */ - while (st <= l->len) { + do { pmatch.rm_so = st; pmatch.rm_eo = l->len; @@ -350,7 +350,7 @@ if (st == (size_t)pmatch.rm_so) break; /* No matches */ - } + } while (st < l->len); } else c = !vflag; >Release-Note: >Audit-Trail: >Unformatted: