From owner-freebsd-bugs@FreeBSD.ORG Wed Jun 27 21:50:01 2012 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 C148D1065672 for ; Wed, 27 Jun 2012 21:50: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 976BC8FC17 for ; Wed, 27 Jun 2012 21:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q5RLo1li090986 for ; Wed, 27 Jun 2012 21:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q5RLo1nt090985; Wed, 27 Jun 2012 21:50:01 GMT (envelope-from gnats) Resent-Date: Wed, 27 Jun 2012 21:50:01 GMT Resent-Message-Id: <201206272150.q5RLo1nt090985@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, "Ronald F.Guilmette" Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 51AA3106564A for ; Wed, 27 Jun 2012 21:41:13 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 29E308FC16 for ; Wed, 27 Jun 2012 21:41:13 +0000 (UTC) Received: by segfault.tristatelogic.com (Postfix, from userid 1237) id A1EA35081B; Wed, 27 Jun 2012 14:41:05 -0700 (PDT) Message-Id: <20120627214105.A1EA35081B@segfault.tristatelogic.com> Date: Wed, 27 Jun 2012 14:41:05 -0700 (PDT) From: "Ronald F.Guilmette" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/169500: /bin/expr improperly requires forward slash to be escaped X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: "Ronald F.Guilmette" List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2012 21:50:01 -0000 >Number: 169500 >Category: bin >Synopsis: /bin/expr improperly requires forward slash to be escaped >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 Jun 27 21:50:01 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Ronald F. Guilmette >Release: FreeBSD 8.3-RELEASE amd64 >Organization: entropy >Environment: 8.3-RELEASE amd64 >Description: According to my reading of Sections 2.8.3.1.1 and 2.8.3.1.2 of the ANSI/IEEE standard 1003.2, a forward slash character (/) is an "ordinary" basic regular expression (BRE) character, and as such can be used in a BRE alone to match itself. As far as I can tell, backslash-escaping of this specific character should not be required within BREs. I note however that /bin/expr does not allow a naked (non-escaped) forward slash character within the right-hand operand of the : binary operator. For example, /bin/expr complains about a "syntax" error on either of the following commands: /bin/expr abcxyz : / /bin/expr abcxyz : "/" I believe that these complaints on the part of /bin/expr are unfounded and inappropriate, and furthermore that they are not consistant with the 1003.2 standard. In contrast, the following command does not produce a syntax error: /bin/expr abcxyz : "\/" This fact leads me to believe that the FreeBSD implementation of /bin/expr may perhaps be improperly treating forward slash as some sort of a delimiter within the BRE operand of the : binary operator. In my opinion, this should be corrected in order to insure maximal compliance with the 1003.2 POSIX standard. *** Please note also that my tests and this report apply strictly and only to /bin/expr. However "expr" may perhaps be implemented as a built-in in some or all shells (e.g. sh, bash, csh, tcsh) and thus, my hope is that whoever attends to this PR will also take the time to look into the possibility that fixes are needed also in those shells. >How-To-Repeat: /bin/expr abcxyz : / /bin/expr abcxyz : "/" >Fix: I haven't looked at the code, so I cannot propose a fix. As I have said above however, my guess is that /bin/expr is in some way treating the right-hand (BRE) operand of the : binary operator as a thing that either is, or that will be, at some point in the internal processing, delimited (on both the left and right) with forward slashes. If so, then /bin/expr should take care to pre-escape any user-supplied forward slashes within the user-supplied BRE operand. >Release-Note: >Audit-Trail: >Unformatted: