From owner-freebsd-bugs@FreeBSD.ORG Wed Sep 8 12:30:01 2010 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 6A09810656BF for ; Wed, 8 Sep 2010 12:30:01 +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 2DD028FC1D for ; Wed, 8 Sep 2010 12:30:01 +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 o88CU1nK044756 for ; Wed, 8 Sep 2010 12:30:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o88CU14Q044753; Wed, 8 Sep 2010 12:30:01 GMT (envelope-from gnats) Resent-Date: Wed, 8 Sep 2010 12:30:01 GMT Resent-Message-Id: <201009081230.o88CU14Q044753@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, Richard Lowe Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6528B10656E0 for ; Wed, 8 Sep 2010 12:22:25 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 551128FC15 for ; Wed, 8 Sep 2010 12:22:25 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o88CMN1d081777 for ; Wed, 8 Sep 2010 12:22:23 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o88CMN0j081776; Wed, 8 Sep 2010 12:22:23 GMT (envelope-from nobody) Message-Id: <201009081222.o88CMN0j081776@www.freebsd.org> Date: Wed, 8 Sep 2010 12:22:23 GMT From: Richard Lowe To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/150384: tr mis-parses '[=]=]' equivalence class 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: Wed, 08 Sep 2010 12:30:01 -0000 >Number: 150384 >Category: bin >Synopsis: tr mis-parses '[=]=]' equivalence class >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: Wed Sep 08 12:30:00 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Richard Lowe >Release: CURRENT >Organization: >Environment: N/A >Description: While working on porting the FreeBSD tr(1) to another system, we hit upon an issue reported by a user that tr didn't process '[=]=]' in the way they expected, that is: echo '[[[[]]]]' | tr -d '[=]=]' Would print an empty string, rather than '[[[[' It seems that in bracket(), tr parses the above equivalence class as a character class, '[=]' followed by '=]', due to the call to strchr() finding the central ] when searching for a terminator then finding that the length of the class is less than 4, and punting on it. >How-To-Repeat: echo "[[[[]]]]" | tr -d '[=]=]' Expecting '[[[[' >Fix: A naive patch, causing bracket() to skip an extra character (that forming the equivalence class) before searching for the terminating ']', is attached. Patch attached with submission follows: diff -u /home/richlowe/str.c /tmp/buffer-content-1887OIZ --- /home/richlowe/str.c 2010-09-08 08:13:18.000000000 -0400 +++ /tmp/buffer-content-1887OIZ 2010-09-08 08:17:36.000000000 -0400 @@ -156,7 +156,7 @@ s->str = p + 1; return (1); case '=': /* "[=equiv=]" */ - if ((p = strchr(s->str + 2, ']')) == NULL) + if ((p = strchr(s->str + 3, ']')) == NULL) return (0); if (*(p - 1) != '=' || p - s->str < 4) goto repeat; Diff finished. Wed Sep 8 08:17:36 2010 >Release-Note: >Audit-Trail: >Unformatted: