summaryrefslogtreecommitdiff
path: root/lib/libc/regex
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2017-07-06 18:21:30 +0000
committerKyle Evans <kevans@FreeBSD.org>2017-07-06 18:21:30 +0000
commit3ea376f69026793829f02a4536e684f25e861e50 (patch)
tree4e25ac30c1ae15bad8b7933ff41b993e147550a3 /lib/libc/regex
parent8f229143b1dfc0dcbd15128ac3c4656a070bfc21 (diff)
Notes
Diffstat (limited to 'lib/libc/regex')
-rw-r--r--lib/libc/regex/regcomp.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index 4d8e912aab97..09b12ccc5a0e 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -114,7 +114,7 @@ static void p_str(struct parse *p);
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 @@ p_branch_fix_tail(struct parse *p, struct branchc *bc)
/*
* 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 @@ p_branch_do(struct parse *p, struct branchc *bc)
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);