Index: head/lib/libc/regex/regcomp.c =================================================================== --- head/lib/libc/regex/regcomp.c +++ head/lib/libc/regex/regcomp.c @@ -114,7 +114,7 @@ static int p_branch_eat_delim(struct parse *p, struct branchc *bc); static void p_branch_ins_offset(struct parse *p, struct branchc *bc); static void p_branch_fix_tail(struct parse *p, struct branchc *bc); -static void p_branch_empty(struct parse *p, struct branchc *bc); +static bool p_branch_empty(struct parse *p, struct branchc *bc); static bool p_branch_do(struct parse *p, struct branchc *bc); static void p_bre_pre_parse(struct parse *p, struct branchc *bc); static void p_bre_post_parse(struct parse *p, struct branchc *bc); @@ -578,13 +578,15 @@ /* * Signal to the parser that an empty branch has been encountered; this will, * in the future, be used to allow for more permissive behavior with empty - * branches. + * branches. The return value should indicate whether parsing may continue + * or not. */ -static void +static bool p_branch_empty(struct parse *p, struct branchc *bc) { SETERROR(REG_EMPTY); + return (false); } /* @@ -600,7 +602,13 @@ ate = p_branch_eat_delim(p, bc); if (ate == 0) return (false); - (void)REQUIRE(ate == 1 && (!bc->outer || MORE()), REG_EMPTY); + else if ((ate > 1 || (bc->outer && !MORE())) && !p_branch_empty(p, bc)) + /* + * Halt parsing only if we have an empty branch and p_branch_empty + * indicates that we must not continue. In the future, this will not + * necessarily be an error. + */ + return (false); p_branch_ins_offset(p, bc); return (true);