Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Mon, 10 Jun 2024 20:57:05 +0300
From: Valery Ushakov <uwe@...err.spb.ru>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com, Nigel Kukard <nkukard@...D.net>
Subject: Re: Re: Different results with regex.h between Musl and Libc

On Mon, Jun 10, 2024 at 11:56:14 -0400, Rich Felker wrote:

> On Mon, Jun 10, 2024 at 02:47:04PM +0300, Valery Ushakov wrote:
> > On Mon, Jun 10, 2024 at 05:38:36 +0000, Nigel Kukard wrote:
> > 
> > > Musl output (Alpine 3.20), musl-1.2.5-r1...
> > > 
> > > The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
> > > Match 0: 37
> > > Match 1:
> > > Match 2: 37
> > > 
> > > Glibc output (ArchLinux), glibc 2.39+r52+gf8e4623421-1...
> > > 
> > > The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
> > > Match 0: 37
> > > Match 1: 37
> > > Match 2:
> > 
> > I'm not sure what POSIX requires here.  The closest I can find after
> > skimming through "9. Regular Expressions" is 9.4.6 that ends with:
> > 
> >   An ERE matching a single character repeated by an '*', '?', or an
> >   interval expression shall not match a null expression unless this is
> >   the only match for the repetition or it is necessary to satisfy the
> >   exact or minimum number of occurrences for the interval expression.
> > 
> >     https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_06
> > 
> > I'm not sure what to read into the absense of the usual "or an ERE
> > enclosed in parentheses" chorus here.
> 
> This looks like a bug. The general requirement (from memory; I don't
> have the spec in front of me now) is that each subexpression, in order
> from the beginning of the regex, matches the maximal-length input it
> can, subject to the overall constraint that the entire regex match the
> earliest (first priority) and maximal length (second priority) input
> it can.
> 
> I guess we need to dig into why this is happening, ensure it's
> actually incorrect, and figure out how to fix it...

You are right, 9.1 Regular Expression Definitions has under "matched":

  Consistent with the whole match being the longest of the leftmost
  matches, each subpattern, from left to right, shall match the
  longest possible string. For this purpose, a null string shall be
  considered to be longer than no match at all.  For example,
  matching the BRE "\(.*\).*" against "abcdef", the subexpression
  "(\1)" is "abcdef", and matching the BRE "\(a*\)*" against "bc",
  the subexpression "(\1)" is the null string.

-uwe

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.