Red Hat Bugzilla – Bug 876766
regex fails to follow POSIX on subexpressions
Last modified: 2016-11-24 10:56:31 EST
Description of problem:
POSIX states <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>:
> <...> The string matched by a contained subexpression shall be within the
> string matched by the containing subexpression. If the containing
> subexpression does not match, or if there is no match for the contained
> subexpression within the string matched by the containing subexpression, then
> back-reference expressions corresponding to the contained subexpression shall
> not match. <...> For example, <...> the expression "\(a\(b\)*\)*\2" fails to
> match 'abab' <...> .
My read of POSIX is that given the string 'abab', if you let
'\(a\(b\)*\)*' match 'abab', then \2 would also have to match 'b', which
is not present at that point in the string. Trying successively shorter
options, if you try to match 'aba', then the second occurrence of the
containing subexpression \(a\(b\)*\) has no matches of the contained
subexpression \(b\), so \2 must fail to match. If you try to match
'ab', then \2 would still have to match 'b'. If you let \(b\)* match
the null string, then \(a\(b\)*\)* matches 'a'; but in this case, there
is no match for the contained subexpression '\(b\)' within the
containing subexpression, so any attempt to use \2 in that scenario must
fail. Finally, if you let '\(a\(b\)*\)*' match the null string, then
you again have a case where \(b\) was not matched, so \2 again fails.
So POSIX is right that 'abab' cannot match, no matter how you slice the
string; and therefore glibc has a bug for claiming 'abab' is the match.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. grep --color '\(a\(b\)*\)*\2' <<< abab
2. printf %s 'regexp(abab, \(a\(b\)*\)*\2, \&-\1-\2)' | m4
1. grep outputs 'abab', with all four bytes highlighted as a match
2. m4 outputs 'abab-a-b', showing that the overall expression matched abab, \1 matched 'a' (at character 3), and \2 matched 'b' (at character 2).
1. grep should have no match
2. m4 should output -1 for no match
See also: https://savannah.gnu.org/bugs/?37737
This package has changed ownership in the Fedora Package Database. Reassigning to the new owner of this component.
This message is a reminder that Fedora 17 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 17. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora
'version' of '17'.
Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version prior to Fedora 17's end of life.
Bug Reporter: Thank you for reporting this issue and we are sorry that
we may not be able to fix it before Fedora 17 is end of life. If you
would still like to see this bug fixed and are able to reproduce it
against a later version of Fedora, you are encouraged change the
'version' to a later Fedora version prior to Fedora 17's end of life.
Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.
This bug is still present in glibc as of the Fedora 19 release: glibc-2.17-11.fc19.x86_64
This is http://sourceware.org/bugzilla/show_bug.cgi?id=52