Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2012 14:41:05 -0700 (PDT)
From:      "Ronald F.Guilmette" <rfg@tristatelogic.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/169500: /bin/expr improperly requires forward slash to be escaped
Message-ID:  <20120627214105.A1EA35081B@segfault.tristatelogic.com>
Resent-Message-ID: <201206272150.q5RLo1nt090985@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120627214105.A1EA35081B>