From 96dca9a81704e0023df29a4749a3bd2b44a557c1 Mon Sep 17 00:00:00 2001 From: Kate F Date: Mon, 27 May 2024 17:45:40 +0100 Subject: [PATCH] Consolidate PCRE unsupported cases. 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. --- include/re/re.h | 2 -- src/libre/ast_analysis.c | 21 ++++++++++----------- src/libre/ast_analysis.h | 3 +-- src/libre/re.c | 6 ++---- src/libre/strerror.c | 2 -- tests/pcre/out48.err | 2 +- tests/pcre/out49.err | 2 +- 7 files changed, 15 insertions(+), 23 deletions(-) diff --git a/include/re/re.h b/include/re/re.h index f876f635a..deab6caed 100644 --- a/include/re/re.h +++ b/include/re/re.h @@ -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, diff --git a/src/libre/ast_analysis.c b/src/libre/ast_analysis.c index 24db8b6d7..b2381e01b 100644 --- a/src/libre/ast_analysis.c +++ b/src/libre/ast_analysis.c @@ -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; @@ -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; @@ -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) { @@ -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", @@ -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; @@ -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; } } @@ -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, diff --git a/src/libre/ast_analysis.h b/src/libre/ast_analysis.h index 5390cce57..0628bd127 100644 --- a/src/libre/ast_analysis.h +++ b/src/libre/ast_analysis.h @@ -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 diff --git a/src/libre/re.c b/src/libre/re.c index 499bbf194..0a2217264 100644 --- a/src/libre/re.c +++ b/src/libre/re.c @@ -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; } diff --git a/src/libre/strerror.c b/src/libre/strerror.c index d66e750a4..009d61df2 100644 --- a/src/libre/strerror.c +++ b/src/libre/strerror.c @@ -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"; diff --git a/tests/pcre/out48.err b/tests/pcre/out48.err index b03d96d7e..4922f0d59 100644 --- a/tests/pcre/out48.err +++ b/tests/pcre/out48.err @@ -1 +1 @@ -tests/pcre/in48.re: Unsupported PCRE edge case +tests/pcre/in48.re:1: Unsupported operator diff --git a/tests/pcre/out49.err b/tests/pcre/out49.err index d22e4cd6d..e7b5bc93f 100644 --- a/tests/pcre/out49.err +++ b/tests/pcre/out49.err @@ -1 +1 @@ -tests/pcre/in49.re: Unsupported PCRE edge case +tests/pcre/in49.re:1: Unsupported operator