From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13378 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Unexpected regex behaviour Date: Mon, 29 Oct 2018 18:59:57 -0400 Message-ID: <20181029225957.GR5150@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1540853887 20003 195.159.176.226 (29 Oct 2018 22:58:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Oct 2018 22:58:07 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Robert =?utf-8?Q?H=C3=B6gberg?= To: musl@lists.openwall.com Original-X-From: musl-return-13394-gllmg-musl=m.gmane.org@lists.openwall.com Mon Oct 29 23:58:03 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gHGTy-00056j-JR for gllmg-musl@m.gmane.org; Mon, 29 Oct 2018 23:58:02 +0100 Original-Received: (qmail 7261 invoked by uid 550); 29 Oct 2018 23:00:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7242 invoked from network); 29 Oct 2018 23:00:10 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13378 Archived-At: On Mon, Oct 29, 2018 at 11:26:19PM +0100, Robert Högberg wrote: > Hi, > > I've noticed that the musl regex implementation behaves slightly > differently than the glibc implementation. I'm attaching a short program > showing the behaviour. > > The difference makes yate (http://yate.null.ro) misbehave when running with > musl (reported here: https://github.com/openwrt/telephony/issues/378). > > Yate uses a regexp like this: > "^\\([[:alpha:]][[:alnum:]]\\+:\\)\\?/\\?/\\?\\([^[:space:][:cntrl:]@]\\+@\\)\\?\\([[:alnum:]._+-]\\+\\|[[][[:xdigit:].:]\\+[]]\\)\\(:[0-9]\\+\\)\\?" > > ... to parse strings like: > "sip:012345678@11.111.11.111:5060;user=phone" > > ... and the matches produced by musl are: > Match 0: 0 - 32 sip:012345678@11.111.11.111:5060 > Match 1: -1 - -1 > Match 2: 0 - 14 sip:012345678@ > Match 3: 14 - 27 11.111.11.111 > Match 4: 27 - 32 :5060 > > ... while glibc produces: > Match 0: 0 - 32 sip:012345678@11.111.11.111:5060 > Match 1: 0 - 4 sip: > Match 2: 4 - 14 012345678@ > Match 3: 14 - 27 11.111.11.111 > Match 4: 27 - 32 :5060 > > What do you think? > > I've only tested musl 1.1.19. Sorry if this is not valid for later > releases. I skimmed the 1.1.20 release notes and didn't find anything regex > related. I haven't checked which of the extensions you're using are supported in musl, but the above is not a conforming POSIX BRE. It would be a lot more readable and portable to use POSIX ERE (REG_EXTENDED) which has the +, ?, and | operators as standard features. This looks like it should work: "^([[:alpha:]][[:alnum:]]+:)?/?/?([^[:space:][:cntrl:]@]+@)?([[:alnum:]._+-]+|[[][[:xdigit:].:]+[]])(:[0-9]+)?" The only reason to use POSIX BRE is if you need backreferences, which are not regular and explicitly not supported in ERE. Rich