8575 regcomp(3C): handle invalid {} constructs consistently

Review Request #645 - Created Aug. 11, 2017 and submitted

Information
Yuri Pankov
illumos-gate
master
8575
7c1403e...
Reviewers
general

upstream (FreeBSD) fix:

commit 39d016e70fde91c131d5276cce9b4bbd4ee71259
Author: kevans <kevans@FreeBSD.org>
Date:   Tue Aug 8 04:10:46 2017 +0000

    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

before the fix:

altair:yuri:~$ echo "a{1,2,3}b" | sed -r "s/{/_/"
a_1,2,3}b
altair:yuri:~$ echo "a{1,2,3}b" | sed "s/\}/_/"
"s/\}/_/": 1: RE error: parentheses not balanced
altair:yuri:~$ echo "a{1,2,3}b" | sed -r "s/{}/_/"
a{1,2,3}b
altair:yuri:~$

after the fix:

altair:yuri:~$ echo "a{1,2,3}b" | LD_LIBRARY_PATH=~/ws/il8575/proto/root_i386/lib sed -r "s/{/_/"
"s/{/_/": 1: RE error: repetition-operator operand invalid
altair:yuri:~$ echo "a{1,2,3}b" | LD_LIBRARY_PATH=~/ws/il8575/proto/root_i386/lib sed "s/\}/_/"
a{1,2,3_b
altair:yuri:~$ echo "a{1,2,3}b" | LD_LIBRARY_PATH=~/ws/il8575/proto/root_i386/lib sed -r "s/{}/_/"
"s/{}/_/": 1: RE error: repetition-operator operand invalid
altair:yuri:~$

debian gnu/linux:

debian:yuri:~$ echo "a{1,2,3}b" | sed -r "s/{/_/"
sed: -e expression #1, char 6: Invalid preceding regular expression
debian:yuri:~$ echo "a{1,2,3}b" | sed "s/\}/_/"
a{1,2,3_b
debian:yuri:~$ echo "a{1,2,3}b" | sed -r "s/{}/_/"
sed: -e expression #1, char 7: Invalid preceding regular expression
debian:yuri:~$
Robert Mustacchi
Toomas Soome
Yuri Pankov
Review request changed

Status: Closed (submitted)

Loading...