From owner-svn-src-head@freebsd.org Tue Aug 8 04:10:48 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5270ADBE781; Tue, 8 Aug 2017 04:10:48 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2F2F96D450; Tue, 8 Aug 2017 04:10:48 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v784AlOG069261; Tue, 8 Aug 2017 04:10:47 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v784AkDP069258; Tue, 8 Aug 2017 04:10:46 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201708080410.v784AkDP069258@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 8 Aug 2017 04:10:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322211 - in head: contrib/netbsd-tests/lib/libc/regex/data lib/libc/regex X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in head: contrib/netbsd-tests/lib/libc/regex/data lib/libc/regex X-SVN-Commit-Revision: 322211 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Aug 2017 04:10:48 -0000 Author: kevans Date: Tue Aug 8 04:10:46 2017 New Revision: 322211 URL: https://svnweb.freebsd.org/changeset/base/322211 Log: regex(3): Handle invalid {} constructs consistently and adjust tests Currently, regex(3) exhibits the following wrong behavior as demonstrated with sed: - echo "a{1,2,3}b" | sed -r "s/{/_/" (1) - echo "a{1,2,3}b" | sed "s/\}/_/" (2) - echo "a{1,2,3}b" | sed -r "s/{}/_/" (3) Cases (1) and (3) should throw errors but they actually succeed, and (2) throws an error when it should match the literal '}'. The correct behavior was decided by comparing to the behavior with the equivalent BRE (1)(3) or ERE (2) and consulting POSIX, along with some reasonable evaluation. Tests were also adjusted/added accordingly. PR: 166861 Reviewed by: emaste, ngie, pfg Approved by: emaste (mentor) MFC after: never Differential Revision: https://reviews.freebsd.org/D10315 Modified: head/contrib/netbsd-tests/lib/libc/regex/data/repet_bounded.in head/contrib/netbsd-tests/lib/libc/regex/data/repet_multi.in head/lib/libc/regex/regcomp.c Modified: head/contrib/netbsd-tests/lib/libc/regex/data/repet_bounded.in ============================================================================== --- head/contrib/netbsd-tests/lib/libc/regex/data/repet_bounded.in Tue Aug 8 00:31:10 2017 (r322210) +++ head/contrib/netbsd-tests/lib/libc/regex/data/repet_bounded.in Tue Aug 8 04:10:46 2017 (r322211) @@ -1,9 +1,24 @@ # the dreaded bounded repetitions -{ & { { -{abc & {abc {abc +# Begin FreeBSD +{ C BADRPT +{ b { { +\{ - { { +\{ bC BADRPT +{} C BADRPT +{} b {} {} +\{\} - {} {} +\{\} bC BADRPT +} & } } +\} & } } +{abc b {abc {abc +{abc C BADRPT +# End FreeBSD {1 C BADRPT {1} C BADRPT -a{b & a{b a{b +# Begin FreeBSD +a{b b a{b a{b +a{b C BADRPT +# End FreeBSD a{1}b - ab ab a\{1\}b b ab ab a{1,}b - ab ab @@ -16,9 +31,15 @@ a{1a C EBRACE a\{1a bC EBRACE a{1a} C BADBR a\{1a\} bC BADBR -a{,2} - a{,2} a{,2} +# Begin FreeBSD +a{,2} b a{,2} a{,2} +a{,2} C BADBR +# End FreeBSD a\{,2\} bC BADBR -a{,} - a{,} a{,} +# Begin FreeBSD +a{,} b a{,} a{,} +a{,} C BADBR +# End FreeBSD a\{,\} bC BADBR a{1,x} C BADBR a\{1,x\} bC BADBR Modified: head/contrib/netbsd-tests/lib/libc/regex/data/repet_multi.in ============================================================================== --- head/contrib/netbsd-tests/lib/libc/regex/data/repet_multi.in Tue Aug 8 00:31:10 2017 (r322210) +++ head/contrib/netbsd-tests/lib/libc/regex/data/repet_multi.in Tue Aug 8 04:10:46 2017 (r322211) @@ -15,7 +15,10 @@ a?{1} C BADRPT a{1}* C BADRPT a{1}+ C BADRPT a{1}? C BADRPT -a*{b} - a{b} a{b} +# Begin FreeBSD +a*{b} b a{b} a{b} +a*{b} C BADRPT +# End FreeBSD a\{1\}\{1\} bC BADRPT a*\{1\} bC BADRPT a\{1\}* bC BADRPT Modified: head/lib/libc/regex/regcomp.c ============================================================================== --- head/lib/libc/regex/regcomp.c Tue Aug 8 00:31:10 2017 (r322210) +++ head/lib/libc/regex/regcomp.c Tue Aug 8 04:10:46 2017 (r322211) @@ -412,6 +412,7 @@ p_ere_exp(struct parse *p, struct branchc *bc) case '*': case '+': case '?': + case '{': SETERROR(REG_BADRPT); break; case '.': @@ -438,9 +439,6 @@ p_ere_exp(struct parse *p, struct branchc *bc) break; } break; - case '{': /* okay as ordinary except if digit follows */ - (void)REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT); - /* FALLTHROUGH */ default: if (p->error != 0) return (false); @@ -454,9 +452,11 @@ p_ere_exp(struct parse *p, struct branchc *bc) return (false); c = PEEK(); /* we call { a repetition if followed by a digit */ - if (!( c == '*' || c == '+' || c == '?' || - (c == '{' && MORE2() && isdigit((uch)PEEK2())) )) + if (!( c == '*' || c == '+' || c == '?' || c == '{')) return (false); /* no repetition, we're done */ + else if (c == '{') + (void)REQUIRE(MORE2() && \ + (isdigit((uch)PEEK2()) || PEEK2() == ','), REG_BADRPT); NEXT(); (void)REQUIRE(!wascaret, REG_BADRPT); @@ -757,7 +757,6 @@ p_simp_re(struct parse *p, struct branchc *bc) (void)REQUIRE(EATTWO('\\', ')'), REG_EPAREN); break; case BACKSL|')': /* should not get here -- must be user */ - case BACKSL|'}': SETERROR(REG_EPAREN); break; case BACKSL|'1':