Skip to content

Commit

Permalink
Consolidate PCRE unsupported cases.
Browse files Browse the repository at this point in the history
My thinking here is that we don't need to categorise these independently from anything else we consider unsupported, because to the caller the reason something is unsupported doesn't matter. This way there's only one situation for a caller to keep track of, and in particular to not need to remember to update whenever we introduce more unsupported things.
  • Loading branch information
katef committed May 29, 2024
1 parent f0da88d commit 96dca9a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 23 deletions.
2 changes: 0 additions & 2 deletions include/re/re.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ enum re_errno {
RE_EERRNO = 1 | RE_MISC,
RE_EBADDIALECT = 2 | RE_MISC,
RE_EBADGROUP = 3 | RE_MISC,
RE_EUNSUPCAPTUR = 4 | RE_MISC,
RE_EUNSUPPPCRE = 5 | RE_MISC,

RE_ENEGRANGE = 0 | RE_MARK | RE_GROUP,
RE_ENEGCOUNT = 1 | RE_MARK | RE_GROUP,
Expand Down
21 changes: 10 additions & 11 deletions src/libre/ast_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ analysis_iter_anchoring(struct anchoring_env *env, struct ast_expr *n)
"%s: LITERAL: rejecting non-optional newline match after $ as unsupported\n",
__func__);
set_flags(n, AST_FLAG_UNSATISFIABLE);
return AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE;
return AST_ANALYSIS_ERROR_UNSUPPORTED;
}
}
break;
Expand Down Expand Up @@ -1010,8 +1010,8 @@ analysis_iter_anchoring(struct anchoring_env *env, struct ast_expr *n)
all_set_past_always_consuming &= child_env.past_always_consuming;
any_sat = 1;
}
} else if (res == AST_ANALYSIS_ERROR_UNSUPPORTED_CAPTURE
|| res == AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE) {
} else if (res == AST_ANALYSIS_ERROR_UNSUPPORTED
|| res == AST_ANALYSIS_ERROR_UNSUPPORTED) {
continue;
} else {
return res;
Expand Down Expand Up @@ -1201,7 +1201,7 @@ analysis_iter_anchoring(struct anchoring_env *env, struct ast_expr *n)
"%s: SUBTRACT: rejecting non-optional newline match after $ as unsupported\n",
__func__);
set_flags(n, AST_FLAG_UNSATISFIABLE);
return AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE;
return AST_ANALYSIS_ERROR_UNSUPPORTED;
}

if (res != AST_ANALYSIS_OK) {
Expand Down Expand Up @@ -1287,9 +1287,9 @@ analysis_iter_reverse_anchoring(struct anchoring_env *env, struct ast_expr *n)
if (env->followed_by_consuming) {
if (env->followed_by_consuming_newline) {
LOG(3 - LOG_ANCHORING,
"%s: END anchor & followed_by_consuming, returning UNSUPPORTED_PCRE\n",
"%s: END anchor & followed_by_consuming, returning UNSUPPORTED\n",
__func__);
return AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE;
return AST_ANALYSIS_ERROR_UNSUPPORTED;
} else {
LOG(3 - LOG_ANCHORING,
"%s: END anchor & followed_by_consuming, setting UNSATISFIABLE\n",
Expand Down Expand Up @@ -1446,9 +1446,8 @@ analysis_iter_reverse_anchoring(struct anchoring_env *env, struct ast_expr *n)
any_set_followed_by_consuming_newline |= child_env.followed_by_consuming_newline;
any_sat = 1;
}
} else if (res == AST_ANALYSIS_ERROR_UNSUPPORTED_CAPTURE
|| res == AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE) {
LOG(3 - LOG_ANCHORING, "%s: got res of UNSUPPORTED_*, bubbling up\n", __func__);
} else if (res == AST_ANALYSIS_ERROR_UNSUPPORTED) {
LOG(3 - LOG_ANCHORING, "%s: got res of UNSUPPORTED, bubbling up\n", __func__);
return res;
} else {
return res;
Expand Down Expand Up @@ -1883,7 +1882,7 @@ analysis_iter_repetition(struct ast_expr *n, struct ast_expr *outermost_repeat_p
*
* An example input that triggers this is '^(($)|)+$' . */
set_flags(n, AST_FLAG_UNSATISFIABLE);
return AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE;
return AST_ANALYSIS_ERROR_UNSUPPORTED;
}
}

Expand Down Expand Up @@ -1994,7 +1993,7 @@ analysis_iter_repetition(struct ast_expr *n, struct ast_expr *outermost_repeat_p
&& repeat_plus_ancestor->u.repeat.max == AST_COUNT_UNBOUNDED);
LOG(3 - LOG_REPETITION_CASES,
"%s: not yet implemented, skipping\n", __func__);
/* return AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE; */
/* return AST_ANALYSIS_ERROR_UNSUPPORTED; */
}

res = analysis_iter_repetition(n->u.group.e, outermost_repeat_parent,
Expand Down
3 changes: 1 addition & 2 deletions src/libre/ast_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ enum ast_analysis_res {

AST_ANALYSIS_ERROR_NULL = -1,
AST_ANALYSIS_ERROR_MEMORY = -2,
AST_ANALYSIS_ERROR_UNSUPPORTED_CAPTURE = -3,
AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE = -4
AST_ANALYSIS_ERROR_UNSUPPORTED = -3
};

enum ast_analysis_res
Expand Down
6 changes: 2 additions & 4 deletions src/libre/re.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,14 @@ re_parse(enum re_dialect dialect, int (*getc)(void *opaque), void *opaque,
if (res < 0) {
ast_free(ast);
if (err != NULL) {
if (res == AST_ANALYSIS_ERROR_UNSUPPORTED_PCRE) {
err->e = RE_EUNSUPPPCRE;
if (res == AST_ANALYSIS_ERROR_UNSUPPORTED) {
err->e = RE_EUNSUPPORTED;
} else if (res == AST_ANALYSIS_ERROR_MEMORY) {
/* This case comes up during fuzzing. */
if (err->e == RE_ESUCCESS) {
err->e = RE_EERRNO;
errno = ENOMEM;
}
} else if (res == AST_ANALYSIS_ERROR_UNSUPPORTED_CAPTURE) {
err->e = RE_EUNSUPCAPTUR;
} else if (err->e == RE_ESUCCESS) {
err->e = RE_EERRNO;
}
Expand Down
2 changes: 0 additions & 2 deletions src/libre/strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ re_strerror(enum re_errno e)
case RE_EERRNO: return strerror(errno);
case RE_EBADDIALECT: return "Bad dialect";
case RE_EBADGROUP: return "Bad group";
case RE_EUNSUPCAPTUR: return "Cannot support captures in this case";
case RE_EUNSUPPPCRE: return "Unsupported PCRE edge case";

case RE_ENEGRANGE: return "Negative group range";
case RE_ENEGCOUNT: return "Negative count range";
Expand Down
2 changes: 1 addition & 1 deletion tests/pcre/out48.err
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tests/pcre/in48.re: Unsupported PCRE edge case
tests/pcre/in48.re:1: Unsupported operator
2 changes: 1 addition & 1 deletion tests/pcre/out49.err
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tests/pcre/in49.re: Unsupported PCRE edge case
tests/pcre/in49.re:1: Unsupported operator

0 comments on commit 96dca9a

Please sign in to comment.