commit 63e8df1d1e24169790f2edfb805c43b982d29a76
parent 48278b3a24901a6139e7559b3fc70ced2bef408c
Author: Nolan Prescott <mail@nprescott.com>
Date: Tue, 26 Apr 2022 02:39:50 -0400
regex: require quantifier minimum in range
Intended to address https://todo.sr.ht/~sircmpwn/hare/633 where
valgrind flags a conditional jump on uninitialized value(s) stemming
from regex.parse_repetition. The source of the uninitialized value
isn't called out in the ticket but is visible with:
valgrind --track-origins=yes .bin/hare-tests regex::find
The POSIX ERE grammar[0] does not specify a quantifier syntax with
undefined minimums (e.g. `{,2}`), this patch will error in such a case
rather than use the void value with `rep_parts.0`
0: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_05_03
Signed-off-by: Nolan Prescott <mail@nprescott.com>
Diffstat:
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/regex/+test.ha b/regex/+test.ha
@@ -304,13 +304,17 @@ fn run_findall_case(
(`^a\|b$`, "a|b", matchres::MATCH, 0, -1),
(`^a\.b$`, "a.b", matchres::MATCH, 0, -1),
(`^a\\b$`, "a\\b", matchres::MATCH, 0, -1),
+ (`^x(abc)\{,2\}$`, "xabc{,2}", matchres::MATCH, 0, -1),
+ (`^x(abc)\{,2\}$`, "xabcabc{,2}", matchres::NOMATCH, 0, -1),
// {m,n}
+ (`^x(abc){2}$`, "xabcabc", matchres::MATCH, 0, -1),
+ (`^x(abc){3}$`, "xabcabc", matchres::NOMATCH, 0, -1),
(`^x(abc){1,2}$`, "xabc", matchres::MATCH, 0, -1),
(`^x(abc){1,2}$`, "xabcabc", matchres::MATCH, 0, -1),
(`^x(abc){1,2}$`, "xabcabcabc", matchres::NOMATCH, 0, -1),
- (`^x(abc){,2}$`, "xabc", matchres::MATCH, 0, -1),
- (`^x(abc){,2}$`, "xabcabc", matchres::MATCH, 0, -1),
- (`^x(abc){,2}$`, "xabcabcabc", matchres::NOMATCH, 0, -1),
+ (`^x(abc){,2}$`, "xabc", matchres::ERROR, 0, -1),
+ (`^x(abc){,2}$`, "xabcabc", matchres::ERROR, 0, -1),
+ (`^x(abc){,2}$`, "xabcabcabc", matchres::ERROR, 0, -1),
(`^x(abc){1,}$`, "xabc", matchres::MATCH, 0, -1),
(`^x(abc){1,}$`, "xabcabc", matchres::MATCH, 0, -1),
(`^x(abc){3,}$`, "xabcabc", matchres::NOMATCH, 0, -1),
diff --git a/regex/regex.ha b/regex/regex.ha
@@ -454,6 +454,10 @@ fn parse_repetition(
};
};
+ if (len(min_str) == 0 && len(max_str) > 0) {
+ return "Invalid repetition minimum value": error;
+ };
+
const rep_len = if (is_single_arg) {
yield len(min_str);
} else {